110,552
社区成员
发帖
与我相关
我的任务
分享
SomeTh some;
public SomeTh Some
{
get { return some; }
set
{
if (some != null)
{
some.PropertyChanged -= some_PropertyChanged;
}
some = value;
if (some != null)
{
some.PropertyChanged += some_PropertyChanged;
}
base.OnPropertyChanged("Some");
}
}
void some_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnPropertyChanged("Some");
}
<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"/>
Model:
public class Student
{
int Age{get;set;}
string Name{get;set;}
}
=================
ViewModel:
public class StudentViewModel : ViewModelBase
{
Student _stu;
public int Age
{
get { return _stu.Age; }
set
{
_stu.Age= value;
base.OnPropertyChanged("Age");
}
}
public string Name
{
get { return _stu.Name; }
set
{
stu.Name= value;
base.OnPropertyChanged("Name");
}
}
}