Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Wpf 控件模板或自定义依赖项属性_Wpf_User Controls_Custom Controls - Fatal编程技术网

Wpf 控件模板或自定义依赖项属性

Wpf 控件模板或自定义依赖项属性,wpf,user-controls,custom-controls,Wpf,User Controls,Custom Controls,我有一个复选框控件,其模板如下: 以下是复选框的XAML片段: <CheckBox Grid.Row="0" Grid.Column="1" Width="62" VerticalAlignment="Center" HorizontalAlignment="Left" IsChecked="{Binding IncludeBlueTrades}" Style="{

我有一个复选框控件,其模板如下:

以下是复选框的XAML片段:

<CheckBox Grid.Row="0" 
          Grid.Column="1" 
          Width="62"
          VerticalAlignment="Center"
          HorizontalAlignment="Left"
          IsChecked="{Binding IncludeBlueTrades}"
          Style="{StaticResource ToggleSwitchCheckBox}"/>

当前,“值:买入”和“卖出”已硬编码到样式中。我想让它们可配置,以便复选框可以传递这些值。基本上,每次我想将复选框用作滑块时,我都应该能够从XAML传递值,如下所示:

<CheckBox Grid.Row="0" 
          Grid.Column="1" 
          Width="62"
          VerticalAlignment="Center"
          HorizontalAlignment="Left"
          ValueOn = "Buy"
          ValueOff = "Sell"
          IsChecked="{Binding IncludeBlueTrades}"
          Style="{StaticResource ToggleSwitchCheckBox}"/>

我理解模板绑定(必须在控件模板中使用)和自定义控件的概念。我在这里困惑的是,我应该使用哪一种方法来获得所取得的结果。我认为它必须是自定义依赖属性-但不是100%确定

我可以张贴样式代码是必要的。有人能帮我看一下代码片段和方向吗


谢谢

定制DP是一个不错的选择。如果有人能分享这个特定示例的代码片段,这是可能的