我需要绑定一个满足两个条件的TextBox
:
- 如果
Text.Length > 0
,则启用 - 如果
user.IsEnabled
为True,则启用
其中user.IsEnabled
是从数据源中获取的。我想知道是否有一种简单的方法来实现这个功能。
以下是XAML代码:
<ContentControl IsEnabled="{Binding Path=Enabled, Source={StaticResource UserInfo}}">
<TextBox DataContext="{DynamicResource UserInfo}" Text="{Binding FirstName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsEnabled="{Binding Path=Text, RelativeSource={RelativeSource Self}, Converter={StaticResource LengthToBool}}"/>
</ContentControl>