1 回答

TA貢獻(xiàn)1876條經(jīng)驗(yàn) 獲得超6個(gè)贊
請(qǐng)首先像這樣設(shè)置數(shù)據(jù)上下文。
Person person1 = new Person() { Name="Test1" };
Person person2 = new Person() { Name="Test2" };
DataContext = new
{
Person1 = person1,
Person2 = person2
};
在像這樣設(shè)計(jì)側(cè)綁定數(shù)據(jù)之后。
<Grid>
<TextBox Text="{Binding Person1.Name,Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
<Grid>
<TextBox Text="{Binding Person2.Name,Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
或(您只能像這樣在設(shè)計(jì)方面進(jìn)行更改)
<Grid DataContext="{Binding person1}">
<TextBox Text="{Binding Name,Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
<Grid DataContext="{Binding person2}">
<TextBox Text="{Binding Name,Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
- 1 回答
- 0 關(guān)注
- 127 瀏覽
添加回答
舉報(bào)