Problem

Treelistbox IsExpanded xaml binding

Posted 4 months ago by Avatar Mike

Hi,

for some reason the binding of IsExpanded does nothing, visibility however works fine.

        <grids:TreeListBox
            Name="ProjectTreeListBox"
            Grid.Row="2"
            IsRootItemVisible="False"
            RootItem="{Binding Projects}">
            <grids:TreeListBox.ItemAdapter>
                <grids:TreeListBoxItemAdapter ChildrenBinding="{Binding Children}" TopLevelExpandabilityDefault="Auto" />
            </grids:TreeListBox.ItemAdapter>
            <grids:TreeListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Image
                            Width="16"
                            Height="16"
                            Stretch="None">
                        </Image>
                        <TextBlock
                            Margin="4,0,0,0"
                            Text="{Binding Name}"
                            TextTrimming="CharacterEllipsis" />
                    </StackPanel>
                </DataTemplate>
            </grids:TreeListBox.ItemTemplate>
            <grids:TreeListBox.ItemContainerStyle>
                <Style TargetType="{x:Type grids:TreeListBoxItem}">
                    <Setter Property="IsExpanded" Value="{Binding Path=Expanded}" />
                    <Setter Property="Visibility" Value="{Binding Path=Visible, Converter={StaticResource BoolToVis}}" />
                </Style>
            </grids:TreeListBox.ItemContainerStyle>
        </grids:TreeListBox>

 For testing purpose I've also tried changing the line to

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

 But all treeitems are collapsed. I'm aware of the IsExpandedBinding property but this doesn't seem work with binding to ReactiveProperty which requires binding to a nested property. For example the binding would look like

public ReactiveProperty<bool> Expanded { get; set;} = new ReactiveProperty<bool>();

 

 IsExpandedBinding="{Binding Expanded.Value}"

 That's why I wanted to do this in the style of treelistboxitem.

[Modified 4 months ago]


Comments (1)

Posted 4 months ago by Actipro Software Support - Cleveland, OH, USA

Hello,

Per the "Expandability" documentation topic:

The TreeListBoxItemAdapter.IsExpandedPath property specifies the property name to watch for in case your item implements INotifyPropertyChanged. When a change to that property is detected, the updated value will be requested by the control. Note that even though a binding can be used via the IsExpandedBinding property, for performance reasons, it is just used temporarily to get/set the value in the adapter methods' default implementations. The binding doesn't persist, and that's why the IsExpandedPath property is required for property change notifications.

IsExpandedPath must be used so that the adapter knows to refresh its value, even when IsExpandedBinding is used.  IsExpandedPath can only be one level though (i.e. "Expanded") and not "Expanded.Value".  

If you'd like us to look into a problem you're having, please make a new simple sample project that shows the issue and send that to our support address, referencing this thread in your email.  Be sure to exclude the bin/obj folders from the ZIP you send and rename the .zip file extension so it doesn't get spam blocked.  Then we can debug it to see what's going on.  Thanks!


Actipro Software Support
Information The latest build of this product (2018.1 build 0671) was released 1 month ago, which was after the last post in this thread.

Add a Comment

Please log in to a validated account to post comments.