C# UWP将两个布尔绑定到IsEnabled属性
我在我的UWP程序中实例化了两个不同的对象。它们的类定义如下所示:C# UWP将两个布尔绑定到IsEnabled属性,c#,uwp,binding,boolean,C#,Uwp,Binding,Boolean,我在我的UWP程序中实例化了两个不同的对象。它们的类定义如下所示: namespace StackOverflow { public class FirstClass : INotifiyPropertyChanged { private bool isEnabled = false; public bool IsEnabled { get => isEnabled; set
namespace StackOverflow
{
public class FirstClass : INotifiyPropertyChanged
{
private bool isEnabled = false;
public bool IsEnabled
{
get => isEnabled;
set
{
isEnabled = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public class SecondClass : INotifiyPropertyChanged
{
private bool isEnabled = false;
public bool IsEnabled
{
get => isEnabled;
set
{
isEnabled = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
<Button Content="Press me if you can" IsEnabled="{x:Bind FirstClass.IsEnabled, Mode=OneWay}"/>
XAML端的绑定当前如下所示:
namespace StackOverflow
{
public class FirstClass : INotifiyPropertyChanged
{
private bool isEnabled = false;
public bool IsEnabled
{
get => isEnabled;
set
{
isEnabled = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public class SecondClass : INotifiyPropertyChanged
{
private bool isEnabled = false;
public bool IsEnabled
{
get => isEnabled;
set
{
isEnabled = value;
NotifyPropertyChanged();
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void NotifyPropertyChanged([CallerMemberName] string propertyName = "") => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
<Button Content="Press me if you can" IsEnabled="{x:Bind FirstClass.IsEnabled, Mode=OneWay}"/>
使用此代码,Button.IsEnabled仅依赖于FirstClass.IsEnabled,我希望实现的是Button.IsEnabled属性依赖于FirstClass.IsEnabled和SecondClass.IsEnabled。我怎样才能得到这样的结果呢
我想实现多重绑定,但它似乎是一个只支持WPF的功能我们无法在xaml中直接绑定两个属性。它似乎只能在代码后操作。当您设置IsEnabled of FirstClass或SecondClass时,然后手动判断IsEnabled of按钮。是否可以绑定两个代码behing变量?例如,创建第三个类,它有两个到FirstClass和SecondClass的独立绑定,将用作源和输出,这将是后面的xaml的输出。可以组合这两个isEnabled属性来确定并只输出一个值,确保绑定值是唯一的。