Treeview失去了对wpf mvvm的关注

时间:2014-11-28 09:28:32

标签: c# wpf mvvm

我的WPF MVVM应用程序中有一个树视图。我还有一个显示treenode值的文本框。现在,当我展开树视图并选择一个节点时,它的值被取出并显示在文本框中。 现在我添加了一个复选框,显示文本框中显示为单词的数字。(例如:11作为一个)。一旦我点击复选框,树视图就会失去焦点。树视图和选择的扩展都丢失了。只有当我再次单击该节点时,该值才会在文本框中显示为单词。我该如何解决这个问题?

<TreeView ItemsSource="{Binding Children}"   Grid.Column="0" MinHeight="200" MinWidth="150" SelectedValuePath="0" >
        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}">
                <Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
                <Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
                <Setter Property="FontWeight" Value="Normal" />
                <Style.Triggers>
                    <Trigger Property="IsSelected" Value="True">
                        <Setter Property="FontWeight" Value="Bold" />                           
                    </Trigger>
                </Style.Triggers>
            </Style>
        </TreeView.ItemContainerStyle>
        <TreeView.Resources>
            <HierarchicalDataTemplate DataType="{x:Type local:TreeViewModel}" 
                                      ItemsSource="{Binding Children}" >
                <TextBlock Text="Data" />
            </HierarchicalDataTemplate>

  <TextBox ScrollViewer.HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" 
                    FontFamily="Courier New" FontSize="13" TextAlignment="Left" 
                 IsReadOnly="True" Grid.Row="0" Grid.Column="1" Text="{Binding Value}" Margin="5,0" />

<CheckBox Content="View In Words" VerticalContentAlignment="Center">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <i:InvokeCommandAction Command="{Binding InWords}" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </CheckBox>            

提前致谢!

0 个答案:

没有答案