0
votes

I am using the tree view control in my silverlight project. I use data binding for binding my model to the tree. This works perfect.

After adding some features to the tree I ran into two problems:

  1. When I change a property on my Model, the tree does not get updated, even after my onproperty changed get called and also my converter is not called?(I need to hide the item when a specific property changes) (Answered)

  2. How do I hide an Item in the tree? (I use Textbox + image as Item template)

  3. Stack panel is hidden, but empty container remains in tree

DataTemplate:

                <common:HierarchicalDataTemplate ItemsSource="{Binding Children}">
                <StackPanel Orientation="Horizontal" Visibility="{Binding IsAvailable, Converter={StaticResource ItemVisibleConverter} ,Mode=TwoWay}"  >
                    <Image Source="{Binding Converter={StaticResource ImageConverter}}"/>
                    <controls:Label Name="myItem" Content="{Binding Description, Converter={StaticResource ItemConverter} ,Mode=TwoWay}" Foreground="Black"/>
                </StackPanel>
            </common:HierarchicalDataTemplate>

Converter: public object Convert(object value, Type targetType, object parameter, ystem.Globalization.CultureInfo culture) { return GetVisibility(value); }

        private Visibility GetVisibility(object value)
    {
        bool IsVisible= (bool)value;
        if (IsAvailableForDownload)
        {
            return Visibility.Visible;
        }
        else
        {
            return Visibility.Collapsed;
        }
    }

Model

    public class MyModel: INotifyPropertyChanged
{
    public bool IsAvailable
    {
        get
        {
            return _IsAvailableForDownload;
        }
        set
        {
            _IsAvailableForDownload = value;
            onPropertyChanged(this, "IsAvailableForDownload");
        }
    }

//Code for on property changed event
}

Regards

1
Can you post the Xaml where you setup the data binding (HierarchialDataTemplate for your tree) as well as a small part of the Model class showing your implementation of INotifyPropertyChanged? Posting the converter code would help too.James Cadd

1 Answers

0
votes
  1. You probably need to make sure that your model implements INotifyPropertyChanged so that the binding system can do its job.

  2. Could you have a property of type Visibility that your item template binds to, or a bool plus a value converter that returns a Visibility value?

    <DataTemplate> <Grid Visibility="{Binding ThisThingsIsVisible}"> <Button Content="{Binding Blah}" /> </Grid> </DataTemplate>

I don't know if this is the recommended way or not - could your bound object not expose hidden items in their collections?