私は単純なものを持っていますWindow
<Window x:Class="BindingProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525" Name="mainWnd">
<TextBox Text="{Binding Path=Simple, ElementName=mainWnd, Mode=OneWayToSource, UpdateSourceTrigger=Explicit}"/>
</Window>
SimpleDependencyProperty
という名前のカスタム
public static DependencyProperty SimpleProperty = DependencyProperty.Register("Simple", typeof(string), typeof(MainWindow), new PropertyMetadata("initial", SimpleChanged));
private static void SimpleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
MessageBox.Show(string.Format("Simple changed from \"{0}\" to \"{1}\"", e.OldValue.ToString(), e.NewValue.ToString()));
}
public string Simple
{
get { return (string)GetValue(SimpleProperty); }
set { SetValue(SimpleProperty, value); }
}
問題は、アプリケーションの起動時にバインディングが初めて設定されるときに、ソース ( SimpleUpdateSource
プロパティの値) が呼び出されなくても更新されMessageBox
、次のメッセージが表示されることです: Simple changed from "initial" to " " .
どうすればそのような行動を取り除くことができますか?