INotifyPropertyChangedを実装していないモデルの1つのプロパティに2つのコントロールをバインドすると、2つのテキストボックスがバインドされ、2つのテキストボックスの内容が同期しているのはなぜですか?他のTextBoxはソースを更新することをどのように通知されますか?2つのWPFコントロールを1つのモデルプロパティにバインドすると、共有バインディングが作成されますか?
モデル:
namespace BindingExample
{
public class PersonModel
{
public string Name { get; set; }
}
}
ビュー:
<Window x:Class="BindingExample.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:BindingExample"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<local:PersonModel x:Key="person"></local:PersonModel>
<Style TargetType="TextBox">
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Width" Value="100"/>
</Style>
</Window.Resources>
<Grid DataContext="{StaticResource person}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}" />
<TextBox Grid.Row="1" Text="{Binding Path=Name, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
</Window>
コードを表示できますか?私はこれが期待される動作だと言っていましたが、あなたは 'INotifyPropertyChanged'を実装していないと言います。この場合、' TextBox'のいずれかが更新されるとは思わないでしょう。 – ChrisF
@ChrisFは、バインディングが単にsourceプロパティの値を読み取るとき、最初は期待しています。 – Clemens
@ Jason Sichは、おそらくDependencyPropertyのソースプロパティですが、これはモデルクラスでは奇妙です。 – Clemens