Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用QuickConverter进行字符串比较_C#_Wpf_Xaml - Fatal编程技术网

C# 使用QuickConverter进行字符串比较

C# 使用QuickConverter进行字符串比较,c#,wpf,xaml,C#,Wpf,Xaml,当Idea.Status==“已验证”时,我想做一些事情,但QuickConverter(-)不允许我使用以下任何一项: Binding="{qc:Binding '$P==Verified',P={Binding Path=Idea.Status}}" Binding="{qc:Binding '$P=="Verified"',P={Binding Path=Idea.Status}}" “已验证”是意外标记。需要空白 无法标记表达式“$p=Verified”。你忘了一个“$”吗 我如何告诉

当Idea.Status==“已验证”时,我想做一些事情,但QuickConverter(-)不允许我使用以下任何一项:

Binding="{qc:Binding '$P==Verified',P={Binding Path=Idea.Status}}"
Binding="{qc:Binding '$P=="Verified"',P={Binding Path=Idea.Status}}"
“已验证”是意外标记。需要空白

无法标记表达式“$p=Verified”。你忘了一个“$”吗


我如何告诉quickconverter和XAML我想与字符串进行比较?

我唯一能想到的方法是使用
qc:MultiBinding

<Grid>
    <Button Content="Hi There !"  VerticalAlignment=" Center" HorizontalAlignment="Center" IsEnabled="{qc:MultiBinding '$P0 == $P1', P0={Binding Status}, P1={Binding Verified}}"></Button>
</Grid>
下面是完整的代码

 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));
    }
}

QuickConverter对字符串文字使用单引号。但是,在标记扩展中,需要转义单引号,因此需要在其前面添加\

所以你的绑定应该是

Binding="{qc:Binding '$P==\'Verified\'',P={Binding Path=Idea.Status}}"

我是这样做的。它的工作原理与所选择的答案相同,但是xaml解析器要快乐得多,并且不会抛出恼人的(假)错误


它可以工作,xaml解析器抛出错误“标记扩展未正确关闭”,但它可以编译并工作。我需要等待3个小时才能授予赏金
Binding="{qc:Binding '$P==\'Verified\'',P={Binding Path=Idea.Status}}"
Binding="{Path=Idea.Status, Converter={qc:QuickConverter '$P == \'Verified\''}}"