これは私がINotifyPropertyChangedのバグだと思います。
2の回避策
第一回避策LableのようなUIコントロールに
の1-割り当てiCounterプロパティが存在する場合があります。
2今度はプロパティの値を変更します。PropertyChangedイベントにはメソッドの参照があり、nullにはなりません。
第二の回避策
エンティティクラスのコンストラクタで
割り当てのPropertyChangedデリゲート
私は、WPF
でデモコード
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.Resources>
<ToolTip x:Key="@tooltip">
<TextBlock Text="{Binding CompanyName}"/>
</ToolTip>
</Grid.Resources>
<TextBlock Text="{Binding Name}" Background="LightCoral" />
<Rectangle Width="200" Height="200" Fill="LightBlue" VerticalAlignment="Center" HorizontalAlignment="Center" ToolTip="{DynamicResource @tooltip}" Grid.Row="1"/>
<Button Click="Button_Click" Grid.Row="2" Margin="20">Click Me</Button>
</Grid>
を与えている会社名は、ツールチップに割り当てられているこちらをご覧ください。
//これはWindow1.Csが パブリックWindow1の() を{ のDataContext = DemoCustomer.CreateNewCustomer()ファイルです。 InitializeComponent();値を変更 }
//ここDemoCustomerクラス
public class DemoCustomer : INotifyPropertyChanged
{
// These fields hold the values for the public properties.
private Guid idValue = Guid.NewGuid();
private string customerName = String.Empty;
private string companyNameValue = String.Empty;
private string phoneNumberValue = String.Empty;
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
// The constructor is private to enforce the factory pattern.
private DemoCustomer()
{
customerName = "no data";
companyNameValue = "no data";
phoneNumberValue = "no data";
}
// This is the public factory method.
public static DemoCustomer CreateNewCustomer()
{
return new DemoCustomer();
}
// This property represents an ID, suitable
// for use as a primary key in a database.
public Guid ID
{
get
{
return this.idValue;
}
}
public string CompanyName
{
get { return this.companyNameValue; }
set
{
if (value != this.companyNameValue)
{
this.companyNameValue = value;
OnPropertyChanged("CompanyName");
}
}
}
public string PhoneNumber
{
get { return this.phoneNumberValue; }
set
{
if (value != this.phoneNumberValue)
{
this.phoneNumberValue = value;
OnPropertyChanged("PhoneNumber");
}
}
}
}
し、最終的に
private void Button_Click(object sender, RoutedEventArgs e)
{
DemoCustomer dc = this.DataContext as DemoCustomer;
dc.CompanyName = "Temp";
}
"ときIショーにPropertyChanged"。これは何を意味するのでしょうか?そして何があなたにnullを与えますか?私がこのコードで見ることのできる唯一のものは、「PropertyChanged」です。 'iCounter'は' int'なので決してnullにはなりません。 'PropertyChanged'がnullの場合、誰もそれにバインドされていないことを意味するので、誰も聞いていません。 –
iCounter用のプロパティ設定ツールでは、 'value = _iCounter; 'ではなく、' _iCounter = value; 'が必要です。 –
どのようにイベントを登録しませんでしたか? –