WPF新手之控件联动

控件之间的绑定,选择TreeView中的某一项,TextBlock中的值随之改变:

<TreeView x:Name="Tree1" ItemsSource="{Binding }" ItemTemplate="{StaticResource TemplateX}"/> <TextBox x:Name="ThyBox" Text="{Binding ElementName=Tree1, Path=SelectedItem, Converter={StaticResource HasSe}, Mode=OneWay}"/>

几个注意点:

①绑定到控件用ElementName而非Source

②只要Path不是基本类型就一定要写Convert

③Mode要注意一下,不想双方同时更新要用OneWay,否则会抛出异常。

你可能感兴趣的:(tree,Path,WPF,binding)