如何将 IsEnabled 与内联表达式绑定?

How to bind IsEnabled with inline expression?

假设我有

<TextBox
    x:Name="txtBox1" />

<!-- more XAML here -->

<TextBox
   x:Name="associatedToTextBox1"
   IsEnabled={Binding ElementName=txtBox1, Path=Text, Magic=txtBox.Text != string.Empty} />

我希望仅当 txtBox1 不为空时才启用 associatedToTextBox1。我认为有一种方法可以将该功能嵌入 xaml,无需转换器。这可能吗?如果是,怎么做?

没有什么比“内联表达式”更好的了。

但是您可以在文本框样式中使用 DataTrigger:

<TextBox x:Name="associatedToTextBox1">
    <TextBox.Style>
        <Style TargetType="TextBox">
            <Style.Triggers>
                <DataTrigger Binding="{Binding Text, ElementName=txtBox1}"
                             Value="">
                    <Setter Property="IsEnabled" Value="False"/>
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </TextBox.Style>
</TextBox>