FormItemというクラスがあるビューモデルがあります。このクラスには、フォームアイテムクラスのプロパティの可視性を制御するフォームアイテムプロパティがあります このプロパティは、別のクラスである可視性プロバイダタイプです。私はクラスの定義を下に与えました。UIへのバインド中に無効なバインディングパスを取得する
今public class FormItem : FormSchema, IDictionary<string, object>, INotifyPropertyChanged
{
public VisibilityStateProvider VisibilityProvider { get; set; }
public FormItem()
{
VisibilityProvider = new VisibilityStateProvider(this);
}
}
public class VisibilityStateProvider : IPropertyStateProvider
{
private FormItem FormItem;
public VisibilityStateProvider(FormItem formItem)
{
FormItem = formItem;
}
public bool this[string key]
{
get
{
return GetVisibilityValue(key);
}
}
private bool GetVisibilityValue(string key)
{
bool result=true;
try
{
returns true or false on basis of some computation
}
}
catch (Exception ex)
{
return false;
}
return result;
}
public void NotifyVisibilityChanged(string key)
{
var a= $"Item[{key}]";
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(a));
}
public event PropertyChangedEventHandler PropertyChanged;
}
我々は次のコードを使用してUWPにおける可視性プロバイダをバインドしようとしている。
<TextBlock Text="Test" Visibility="{x:Bind ViewModel.FormItem.VisibiltyProvider[key],Convertor = {StaticResource BoolToVisibilityOCnvertor}}"/>
我々が無効な結合パスを取得しています。今我々が直接プロパティにバインドしている場合、我々はnullとしてプロパティの変更を取得しています。限り
public class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged
- それは、のようなものを観察可能な辞書を持っている必要とされるもののように見える、あなたのコードスニペットから Binding through IDictionary<string,object> property changed event handler is null
を。 – tobey
参照のために私の前の質問へのリンクを参照してください https://stackoverflow.com/questions/46997601/binding-through-idictarystring-object-property-changed-event-handler-is-nul?answertab=active# tab-top – tobey
このコードについてはわかりません:var a = $ "Item [{key}]";具体的には、「アイテム」はどこですか?私は単にpropertyynameを使用してPropertychangedを呼び出します。 – cmathews