-1

I a have typical label that I want to control its visibility by a property that is null/empty or not.

I've put breakpoints and also log and it seems that return value is true but still it does not show the element. When I scroll my listview then they are visible but sometimes still not.. There are several items, sometimes some of them are visible sometimes not.. it is changable..
here my converter

public class TestBooleanConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        var result=  value != null && !value.ToString().Equals("");
        Console.WriteLine("Result: " +result);
        return result;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

and the property

    public string LocalizedReadoutDescription
    {
        get
        {
            Console.WriteLine("Description: " + dataItem.Description);
            string localizedDescription = null;
            if (!string.IsNullOrEmpty(this.dataItem.Description))
            {
                string[] descriptionKeyParts = this.dataItem.Description.Split(';');
                localizedDescription = descriptionKeyParts[0];
                if (!string.IsNullOrEmpty(localizedDescription))
                {
                    localizedDescription = 
                   this.getLocalizedString(Constants.Localization.LogicalItemDescriptionFmt, 
                     localizedDescription);
                }
            }

            return localizedDescription;
        }
    }

and Xaml Code

<ContentView.Resources>
  <converters:TestBooleanConverter x:Key="nullToBoolConverter"/>
   .....
</ContentView.Resources>

    .....

<StackLayout Orientation="Horizontal" Margin="4,2" Grid.Column="1"  VerticalOptions="StartAndExpand" 
 HorizontalOptions="FillAndExpand" Spacing="0" BackgroundColor="White">
       <StackLayout.GestureRecognizers>
          <TapGestureRecognizer Tapped="Help_Tapped" CommandParameter="{Binding}"/>
       </StackLayout.GestureRecognizers>
       <Label x:Name="HelpLabel" Style="{StaticResource InfoIconLabel}" Text="{x:Static resx:UI.Icon_Info}" Margin="0" 
        HorizontalOptions="EndAndExpand" VerticalOptions="Start" IsVisible="{Binding LocalizedReadoutDescription,
       Converter={StaticResource nullToBoolConverter}}" FontSize="Micro" LineBreakMode="NoWrap"/>
 </StackLayout>

I feel that, even it returns true, but it uses the previous rows value. but only this part does not update. label names, values are updated, but only some items' visibility is not updating..

where is my mistake?

Update:

I've created an event for property change of the label that I want to control its visibility. I can see that, the IsVisible is always true but on the GUI, only one item is visible.. but when I scroll, several are visible, and when I scroll more then all items are visible as it must be

    private void HelpLabel_OnPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        if (e.PropertyName.Equals("IsVisible"))
        { 
           // I check => ((Xamarin.Forms.Label)sender).IsVisible 
           //always true
       }
    }
5
  • you are binding to LocalizedReadoutDescription but your property is named LocalizedParamDescription
    – Jason
    Commented Oct 24, 2019 at 13:51
  • @Jason thank you for the comment. sorry I've added the wrong code. I've just fixed
    – boss
    Commented Oct 24, 2019 at 14:03
  • if this is happening in the context of a ListView, it may be a caching issue. Also, if you are updating the value dynamically, you need to use INotifyPropertyChanged
    – Jason
    Commented Oct 24, 2019 at 14:12
  • the value does not change dynamically.. the caching seems more logical.. I am using telerik's listview
    – boss
    Commented Oct 24, 2019 at 14:13
  • 1
    Is the value of LocalizedReadoutDescription going to change after the XAML is displayed? That is, are you expecting these things to start out visible and then hide themselves? If so, what are you doing to inform the UI that the value of LocalizedReadoutDescription has changed and it needs to update the target property? If you think that some rows are displaying values for other rows, that's likely to be a bug in your viewmodel classes. Telerik's code is in production and is widely used, so it's likely to be much better tested and debugged than the code you're writing at the moment. Commented Oct 24, 2019 at 14:32

1 Answer 1

0

I have found the problem. It was not regarding cache or informing UI element. Somehow it was regarding the item's height. I've gave a height and heightrequest value, and then it works always.. weird..

Not the answer you're looking for? Browse other questions tagged or ask your own question.