我设法进一步得到我只读了一下休息后复选框,现在我想在一个合理的优雅形态的功能。问题是我使用了一些黑客来使其工作,虽然这不是一场灾难,但它会更好地做到这一点。添加自定义依赖属性来控制模板在XAML
总结一下:我想经常看复选框,单击时是不自检,而不是点击事件触发后台工作,后来就导致一个变量来进行更新。该变量绑定到checkbox.ischecked,然后用新值更新。
我想用基于这样的理念在这里控件模板:
A read-only CheckBox in C# WPF
我已经修改了这一点,并剥离出来的东西,我想我并不需要(也许是不明智),并结束了:如上所述
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Microsoft_Windows_Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
<!-- -->
<Style x:Key="ReadOnlyCheckBoxStyle" TargetType="{x:Type CheckBox}" >
<Setter Property="Control.Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CheckBox}">
<BulletDecorator SnapsToDevicePixels="true" Background="Transparent">
<BulletDecorator.Bullet>
<Microsoft_Windows_Themes:BulletChrome Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
RenderMouseOver="{TemplateBinding IsMouseOver}"
IsChecked="{TemplateBinding Tag}">
</Microsoft_Windows_Themes:BulletChrome>
</BulletDecorator.Bullet>
<ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
RecognizesAccessKey="True" />
</BulletDecorator>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Foreground" Value="{StaticResource {x:Static SystemColors.GrayTextBrushKey}}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
此复选框的作品,我这样称呼它:
<CheckBox x:Name="uiComboBox" Content="Does not set the backing property, but responds to it."
Style="{StaticResource ReadOnlyCheckBoxStyle}" Tag="{Binding MyBoolean}" Click="uiComboBox_Click"/>
我做的破解是使用'标记'DependencyProperty将数据绑定到控制模板中。这绕过了通常导致复选框自检的任何机制。要恢复到正常的演技复选框只是改变结合标记的结合和器isChecked的BulletDecorator内设置TemplateBinding来代替器isChecked的标签。
所以我想我的问题是:
- 有我的坚持错误的结束?是否有一个地方可以重写任何机制导致盒子自检的机制?也许在ControlTemplate触发器?
- 这是个好主意来绕去消除任何备用XAML,我觉得只是被从默认的CheckBox带来的还是应该尽量保持完整替代所有样式?
- 如果我做的是不是太疯狂了,我可以添加在XAML一个依赖属性,这样我就不必使用Tag属性?
- 它也发生,我认为也许是我真正想要的是一个按钮控件,看起来像一个复选框,也许在顶部通常动画复选框,我将数据绑定到的图形一种无形的按钮。对这一计划的任何想法也将非常受欢迎。
非常感谢
埃德