我有一个" A"和Class" VisibilityStateProvider"每当A类的任何键发生变化时,我都会调用VisibilityStateProvider的NotifyVisibilityChanged,但GetVisibilityValue(key)方法永远不会被调用。并且可见性不会在UI上获得更新。
感谢您的帮助!!
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 >
答案 0 :(得分:0)
我还没有检查完整的代码,所以在这里我将分享一个你需要知道的事情作为开始。在您的代码中,GetVisibilityValue(key)永远不会被调用,因为您没有以正确的方式调用它。请尝试以下代码作为测试:
public A()
{
VisibilityProvider = new VisibilityStateProvider(this);
var something = VisibilityProvider["test"];
}
这里只有你像第二行一样打电话,才能调用下面的代码:
get
{
return GetVisibilityValue(key);
}