Newbie binding confusion

3 posts, 0 answers
  1. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 18 Mar 2010 Link to this post

    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. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 18 Mar 2010 Link to this post

    Alright, my style selector is working, but now how do I get the style selector to fire again as I change properties?
  3. DevCraft banner
  4. David Brubacher
    David Brubacher avatar
    29 posts
    Member since:
    Mar 2010

    Posted 19 Mar 2010 Link to this post

    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.

Back to Top