2020-10-15
程序员文章站
2022-06-09 17:56:08
...
嵌套类中绑定控件做法
假设有个
Person { Name,Age,book } 其中 Book{Title ,ISBN}
Name,Age绑定比较简单 Text="{Binding Path=Name}" 即可
但是Book的Title和ISBN的绑定需要指定为 book.Title 和book.ISBN
<TextBlock Text="Name:" Grid.Row="0" Height="20"/>
<TextBox x:Name="txt_Name" Grid.Row="0" Grid.Column="1" Text="{Binding Path=Name}" FontSize="16" Height="22"/>
<TextBlock Text="Age:" Grid.Row="1" Height="20"/>
<TextBox x:Name="txt_Age" Grid.Row="1" Grid.Column="1" Text="{Binding Path=Age}" FontSize="16" Height="22"/>
<TextBlock Text="Title:" Grid.Row="2" Height="20" />
<TextBox x:Name="txt_Title" Grid.Row="2" Grid.Column="1" Text="{Binding Path=book.Title}" FontSize="16" Height="22"/>
<TextBlock Text="ISBN:" Grid.Row="3" Height="20"/>
<TextBox x:Name="txt_ISBN" Grid.Row="3" Grid.Column="1" Text="{Binding Path=book.ISBN}" FontSize="16" Height="22"/>
下一篇: WCF中常用的binding方式
推荐阅读