0
我有一個類「A」和類「VisibilityStateProvider」每當任何關鍵的類A改變,那時我調用VisibilityStateProvider的NotifyVisibilityChanged但GetVisibilityValue(key)方法永遠不會調用。可見性不會在UI上得到更新。UWP綁定不工作
感謝您的幫助!
public class A: IDictionary<string, object>, INotifyPropertyChanged
{
public VisibilityStateProvider VisibilityProvider { get; set; }
public A()
{
VisibilityProvider = new VisibilityStateProvider(this);
}
}
public class VisibilityStateProvider : IPropertyStateProvider
{
private A A;
public VisibilityStateProvider(A a)
{
A= a;
}
public bool this[string key]
{
get
{
return GetVisibilityValue(key);
}
}
private bool GetVisibilityValue(string key)
{
//returns true or false on basis of some condition.
}
public void NotifyVisibilityChanged(string key)
{
var a= $"Item[{key}]";
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(a));
}
}
public interface IPropertyStateProvider : INotifyPropertyChanged
{
bool this[string key] { get;}
}
//xaml
<TextBox Text="{Binding A[mf_number1], Mode=TwoWay}" Visibility="{Binding A.VisibilityProvider[mf_number1],Converter={StaticResource BoolToVisibilityConverter}}" ></TextBox >
做這樣GetVisibilityValue方法被調用,但我希望通過xaml綁定來調用它 –