This is a migrated thread and some comments may be shown as answers.

Newbie binding confusion

2 Answers 31 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
David Brubacher
Top achievements
Rank 1
David Brubacher asked on 18 Mar 2010, 03:25 PM
I have successfully bound a treeview to a class with an observable collection property. Lets call the collection objects Entry and yes, its properties implement INotifyPropertyChanged.

Now I am trying to bind parts of each node to properties on Entry. For instance, if an Entry is Visible, I want the RadTreeViewItem to be IsEnabled =  False.

I've created two styles based on the style generated in the customization walkthrough of Rad Controls Silverlight Courseware (page 622) like so;

 

 

<Style x:Key="VisibleLayer" TargetType="nav:RadTreeViewItem"> 

 

    <Setter Property="HorizontalContentAlignment" Value="Left"/>

 

 

 

    <Setter Property="VerticalContentAlignment" Value="Center"/>

 

 

 

    <Setter Property="BorderThickness" Value="1"/>

 

 

    <Setter Property="Padding" Value="1 0 5 0"/>

 

 

    <Setter Property="IsDropAllowed" Value="False"/>

 

 

 

    <Setter Property="ItemsOptionListType" Value="Default"/>

 

 

 

    <Setter Property="IsEnabled" Value="True"/>

 

 

 

    <Setter Property="MinHeight" Value="24"/>

 

 

 

    <Setter Property="ItemsPanel">

 

 

 

        <Setter.Value>

 

 

 

            <ItemsPanelTemplate>

 

 

 

                <Telerik_Windows_Controls_TreeView:TreeViewPanel VerticalAlignment="Bottom"/>

 

 

 

            </ItemsPanelTemplate>

 

 

 

        </Setter.Value>

 

 

 

    </Setter>

 

 

 

</Style>

And I've created an ItemsContainerStyleSelector
<local:LayerStyleSelector

 

 

 

 

 

    x:Key="LayerStyleSelector"

 

 

 

 

    InvisibleStyle="{StaticResource InvisibleLayer}"

 

 

 

 

    VisibleStyle="{StaticResource VisibleLayer}" />

and referenced it within the data template
<telerik:HierarchicalDataTemplate x:Key="LayerDataTemplate"

 

 

 

 

 

    ItemContainerStyleSelector="{StaticResource LayerStyleSelector}">

but I don't see any change to my items. I've even forced my style selector to only return an odd looking style to make sure SelectStyle is firing but with no changes.

What am I missing? Is this even the best way to achieve what I want?

Thanks!

 

 

 

 

 

 

 

2 Answers, 1 is accepted

Sort by
0
David Brubacher
Top achievements
Rank 1
answered on 18 Mar 2010, 08:30 PM
Alright, my style selector is working, but now how do I get the style selector to fire again as I change properties?
0
David Brubacher
Top achievements
Rank 1
answered on 19 Mar 2010, 03:16 PM
Figured this out by going a very different route as indicated by other posts found while searching (and searching)
I got rid of the selectors, etc and do it all in code, e.g.
        private void ApplyScale(ItemsControl control)  
        {  
            foreach (object t in control.Items)  
            {  
                var treeItem = control.ItemContainerGenerator.ContainerFromItem(t) as RadTreeViewItem;  
                if (treeItem != null)  
                {  
                    var entry = treeItem.Item as Entry;  // Entry is the base class
                    if (entry is GroupEntry)             // GroupEntry adds an ObservableCollection<Entry> to Entry
                        ApplyScale(treeItem);  
                    else 
                    {  
                        if (entry != null)  
                            treeItem.IsEnabled = entry.Visible = entry.Minimum <= _ZoomScale && entry.Maximum >= _ZoomScale;  
                    }  
                }  
            }  
        } 

The tricky bit was the line with ItemContainerGenerator.
Thanks to all who had a look.

Tags
TreeView
Asked by
David Brubacher
Top achievements
Rank 1
Answers by
David Brubacher
Top achievements
Rank 1
Share this question
or