Silverlight TreeViewItem binding to IsSelected, how?

When reading the TreeView message and binding to the view model (http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx) it seems that binding the TreeViewItem IsSelected property is possible. However, I have the following code that always fails on initialization () because it is trying to set a read-only property?

       <sdk:TreeView Grid.Column="0" Grid.Row="2" Style="{StaticResource TreeViewStyle}" 
                  ItemsSource="{Binding tvData}" > 
            <sdk:TreeView.ItemContainerStyle> 
                <Style TargetType="sdk:TreeViewItem"> 
                    <Setter Property="IsEnabled" Value="True" /> 
                    <Setter Property="IsExpanded" Value="True" /> 
                    <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" /> 
                </Style> 
            </sdk:TreeView.ItemContainerStyle> 
            <sdk:TreeView.ItemTemplate> 
                <sdk:HierarchicalDataTemplate ItemsSource="{Binding Children}"> 
                    <StackPanel Orientation="Horizontal"> 
                        <TextBlock Text="{Binding ItemName}" FontWeight="{Binding ItemFontWeight}"/> 
                    </StackPanel>                         
                </sdk:HierarchicalDataTemplate>                     
            </sdk:TreeView.ItemTemplate>
+3
source share
2 answers

Setter Style. , , Setter.Value. Xaml , . , Setter , IsSelected, , , , , .

+2

Source: https://habr.com/ru/post/1773239/


All Articles