binding mode, trigger

This commit is contained in:
2023-06-20 15:16:23 +09:00
parent 9d11cb889a
commit b69c06f4c4
2 changed files with 5 additions and 3 deletions

View File

@@ -9,9 +9,9 @@
<StackPanel>
<Label HorizontalAlignment="Center">--- By XAML Code ---</Label>
<TextBox x:Name="tbxByXaml" VerticalAlignment="Center"/>
<Label x:Name="lblByXaml" Height="30" VerticalAlignment="Center" Content="{Binding ElementName=tbxByXaml, Path=Text}"/>
<TextBox x:Name="tbxByXaml2" Height="30" VerticalAlignment="Center" Text="{Binding ElementName=tbxByXaml, Path=Text, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
<Label HorizontalAlignment="Center">--- By Code Behind ---</Label>
<TextBox x:Name="tbxByCodeBehind"/>
<Label x:Name="lblByCodeBehind" Height="30" VerticalAlignment="Center"/>
<TextBox x:Name="tbxByCodeBehind2" Height="30" VerticalAlignment="Center"/>
</StackPanel>
</Window>

View File

@@ -31,7 +31,9 @@ namespace DataBindingSample
Binding binding = new Binding();
binding.Source = tbxByCodeBehind;
binding.Path = new PropertyPath(TextBox.TextProperty);
lblByCodeBehind.SetBinding(Label.ContentProperty, binding);
binding.Mode = BindingMode.TwoWay;
binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;
tbxByCodeBehind2.SetBinding(TextBox.TextProperty, binding);
}
}
}