我想在Idea.Status ==“已验证”时执行某些操作,但QuickConverter(1 - 2)不允许我使用以下任何内容:
Binding="{qc:Binding '$P==Verified',P={Binding Path=Idea.Status}}"
Binding="{qc:Binding '$P=="Verified"',P={Binding Path=Idea.Status}}"
'已验证'是一个意外的令牌。期待白色空间。
无法将表达式标记为“$ P =已验证”。你忘记了'$'吗?
如何告诉quickconverter和XAML我想要与字符串进行比较?
答案 0 :(得分:8)
QuickConverter对字符串文字使用单引号。但是在标记扩展中,您需要转义单引号,因此您需要在它之前添加\。
所以你的绑定应该是
Binding="{qc:Binding '$P==\'Verified\'',P={Binding Path=Idea.Status}}"
答案 1 :(得分:3)
Binding="{Path=Idea.Status, Converter={qc:QuickConverter '$P == \'Verified\''}}"
答案 2 :(得分:2)
我能想出的唯一方法是使用qc:MultiBinding
<Grid>
<Button Content="Hi There !" VerticalAlignment=" Center" HorizontalAlignment="Center" IsEnabled="{qc:MultiBinding '$P0 == $P1', P0={Binding Status}, P1={Binding Verified}}"></Button>
</Grid>
Verified
被定义为ViewModel / CodeBehind
public String Verified { get; set; }
这里是完整的代码
public partial class MainWindow : Window,INotifyPropertyChanged
{
public String Verified = "Verified";
private String _status = "Verified";
public String Status
{
get
{
return _status;
}
set
{
if (_status == value)
{
return;
}
_status = value;
OnPropertyChanged();
}
}
public MainWindow()
{
InitializeComponent();
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
}