c# - BooleanToVisibilityConverter 折叠/显示 TabItem
问题描述
在MainWindow.xaml我有以下...
<Window.Resources>
<BooleanToVisibilityConverter x:Key="BooleanToVisibility" />
</Window.Resources>
// Tab control
<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=DebugTabState, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>
在MainWindow.xaml.cs我有以下...
public bool DebugTabState
{
get
{
return AppData.EnableDebuggingCheckBox;
}
}
在DebugSettings.xaml我有以下...
<CheckBox x:Name="EnableDebuggingCheckBox" Content="Enable Debugging" IsChecked="{Binding Path=EnableDebugging}" />
在DebugSettings.xaml.cs我有以下...
public bool EnableDebugging
{
get
{
return AppData.EnableDebuggingCheckBox;
}
set
{
AppData.EnableDebuggingCheckBox = value;
}
}
最后,在AppData.cs我有以下...
private bool _enableDebuggingCheckBox;
public bool EnableDebuggingCheckBox
{
get
{
return _enableDebuggingCheckBox;
}
set
{
_enableDebuggingCheckBox = value;
OnPropertyChanged("EnableDebuggingCheckBox");
}
}
选中和取消选中 EnableDebuggingCheckBox 会按预期将值更新为 true 或 false,但 DebugTab 没有隐藏或显示。我错过了什么吗?
谢谢!
解决方案
如果 Appdata 是 MainWindow 中的公共属性,请将绑定更改为:
<TabItem x:Name="DebugTab" Header="Debug" Visibility="{Binding Path=AppData.EnableDebuggingCheckBox, Converter={StaticResource ResourceKey=BooleanToVisibility}}">
// Some content
</TabItem>
然后,您可以删除 MainWindow.DebugTabState。
或者,在 MainWindow 中建议从 AppData 中的 INotifyPropertyChange 并在 EnableDebuggingCheckBox 更改时引发 PropertyChanged 事件
推荐阅读
- java - 模式观察者和 Spring
- javascript - Javascript复制粘贴奇怪的行为
- php - ACF 转发器按日期子字段排序
- node.js - 在 mongoose.js 中哪种创建和更新文档的方式更好?
- powerbi - Power Bi ,列中的平均常数值而不是滚动平均值?
- node.js - 如何更改 Firebase 提供的文件的目录/文件路径?
- api - 登录 API 方法在 Xamarin 表单中返回 400 错误请求
- javascript - 如何在传单 MarkerClusterGroup 中打开特定标记的弹出窗口?
- xslt - XSL 在最后一个元素出现时将一个级别元素移动到另一个元素中
- python - 使用pandas python根据来自另一个数据帧的数据更新数据帧