私の問題は「スコープ」と思われますが、それは正しい用語であるとは確信していません。私は、カスタムオブジェクト内のプロパティが設定されているときに、再評価するための読み取り専用リストに通知したいと思います。私はそれが単にその存在を認識していないと信じています。たぶん私は考えることができないこの周りの簡単な方法がありますが、私は空白を描いています。クラス内のクラスのプロパティでINotifyPropertyChangedを使用する方法..?
私はこれを言葉にするのが難しいと思っています。だから、ここで簡単なコードを書いています。
private CvarAspectRatios _aspectRatio = new CvarAspectRatios("none", GetRatio());
public CvarAspectRatios AspectRatio
{
get { return _aspectRatio; }
set
{ // This setter never gets hit since I bind to this
if (value != null) // object's 'Value' property now.
{
_aspectRatio = value;
NotifyPropertyChanged("AspectRatio");
NotifyPropertyChanged("ResolutionList"); // I want to inform ResolutionList
} // that it needs to repopulate based
} // on this property: AspectRatio
}
private ResolutionCollection _resolutionList = ResolutionCollection.GetResolutionCollection();
public ResolutionCollection ResolutionList
{
get
{
ResolutionCollection list = new ResolutionCollection();
if (AspectRatio != null && AspectRatio.Value != null)
{
foreach (Resolutions res in _resolutionList.Where(i => i.Compatibility == AspectRatio.Value.Compatibility))
{
list.Add(res);
}
return list;
}
return _resolutionList;
}
}
CvarAspectRatiosクラス::オブジェクト内
プロパティとは、私はにデータバインディングしています
public class CVarAspectRatios : INotifyPropertyChanged
{
private string _defaultValue;
public string DefaultValue
{
get { return _defaultValue; }
set { _defaultValue = value; NotifyPropertyChanged("DefaultValue"); }
}
private AspectRatios _value;
public AspectRatios Value
{
get { return _value; }
set
{
_value = value;
NotifyPropertyChanged("Value");
NotifyPropertyChanged("ResolutionList"); // This value gets set, and I'd like for ResolutionList to update
} // but it cannot find ResolutionList. No errors or anything. Just
} // no update.
public AspectRatios() { }
public AspectRatios(string defaultValue, AspectRatios val)
{
DefaultValue = defaultValue;
Value = val;
}
// Implementation of INotifyPropertyChanged snipped out here
}
あなたの人々はどう思いますか?サンプルアプリケーションをご希望の場合は、私は1つをアップすることができます。
Sir、それはすばらしくシンプルで、うまくいく。ありがとう! – erodewald
DataGridViewにバインドされているときにこれを行うと、InvalidOperationExceptionが発生します。 'BindingSourceを独自のデータソースにすることはできません。 DataSourceプロパティとDataMemberプロパティをBindingSourceを参照する値に設定しないでください。 ' – mphair
何も設定されていないため、上記の実装によってエラーが発生するかどうかはわかりません。 – Adrian