2017-11-18 7 views
0

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

答えて

0

:私はすでに、次の質問にStackOverflowの上で質問をしてきましたバインディングは、あなたがキー値を知っているならば、あなたは直接 "キー"ではなくバインディングでそれを使うことができます。 {「ShowTextBlock」:真}のTextBlockが辞書に基づいて表示する必要がある場合たとえば、あなたのケースでは、あなたは次のようにバインドすることができます - 私は、プロパティの変更にヌルとしても、ハンドラを取得しています。この場合

<TextBlock Visibility="{Binding Dictionary[ShowTextBlock], Converter={StaticResource BoolToVisConverter}" /> 
+0

を。 – tobey

+0

参照のために私の前の質問へのリンクを参照してください https://stackoverflow.com/questions/46997601/binding-through-idictarystring-object-property-changed-event-handler-is-nul?answertab=active# tab-top – tobey

+0

このコードについてはわかりません:var a = $ "Item [{key}]";具体的には、「アイテム」はどこですか?私は単にpropertyynameを使用してPropertychangedを呼び出します。 – cmathews

関連する問題