我有一个带有文本框和按钮的用户控件,它们绑定到viewmodel的属性。
<Grid>
<StackPanel>
<TextBox Text=" Hi" IsEnabled="{Binding IsReadOnly, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<Button Content="B" Visibility="{Binding IsVisible, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BooleanToVisibilityConverter}}"></Button>
</StackPanel>
</Grid>
如果没有为此用户控件提供datacontext,如何使按钮不可见?
答案 0 :(得分:8)
FallbackValue
<Button Content="B" Visibility="{Binding IsVisible,
UpdateSourceTrigger=PropertyChanged,
Converter={StaticResource BooleanToVisibilityConverter}},
FallbackValue=Collapsed"></Button>