Binding问题
下面只是描述问题而写的例子,不用探究逻辑关系的合理与否。
public class StudentGroup : ViewModelBase { Student _stu; public Student Stu { get { return _stu; } set { _stu = value; base.OnPropertyChanged("Stu"); } } } public class Student : ViewModelBase { int _age; string _name; public int Age { get { return _age; } set { _age = value; base.OnPropertyChanged("Age"); } } public string Name { get { return _name; } set { _name = value; base.OnPropertyChanged("Name"); } } }
<DataTemplate x:Key="myParamTemplate"> <Border Name="border" BorderBrush="Aqua" BorderThickness="1" Padding="5" Margin="5"> <Grid> <Grid.RowDefinitions> <RowDefinition/> </Grid.RowDefinitions> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition /> <ColumnDefinition /> </Grid.ColumnDefinitions> <TextBlock Grid.Row="0" Grid.Column="0" Text="Param:"/> <TextBox Grid.Row="0" Grid.Column="1" Text="{Binding Path=Age,UpdateSourceTrigger=PropertyChanged}" /> <TextBlock Grid.Row="0" Grid.Column="2" Text="{Binding Path=Name,UpdateSourceTrigger=PropertyChanged}"/> </Grid> </Border> </DataTemplate><ContentControl Content="{Binding Path=Stu,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" ContentTemplate="{StaticResource myParamTemplate}" Background="Red"/>