因此,我正在尝试为正在处理的应用程序创建用户控件。基本上ToggleButton是ComboBox。我能够ComboBox按照设计人员的要求在VS2015中模拟用户控件的一部分,但是我觉得我的想法并不是最好的方法。
首先,这是其外观截图的链接:https : //www.dropbox.com/s/019f4xqgu8r4i0e/DropDown.png
为此,我最终创建了3种不同的ComboBoxItem样式。第一个将a CheckBox,a TextBlock与the ContentPresenter和a 组合在一起Rectangle。第二个只有一个Separator,而最后一个只有TextBlock一个ContentPresenter。这是我的XAML,在本UserControl.Resources节中声明:
<Style x:Key="cbTestStyle" TargetType="{x:Type ComboBoxItem}">
<Setter Property="SnapsToDevicePixels" Value="True"/>
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="OverridesDefaultStyle" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ComboBoxItem">
<Border Name="Border"
Padding="5"
Margin="2"
BorderThickness="2"
CornerRadius="0"
BorderBrush="Transparent">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="75"/>
<ColumnDefinition Width="15"/>
</Grid.ColumnDefinitions>
<CheckBox Grid.Column="0"
IsChecked="{Binding Path=IsSelected, RelativeSource={RelativeSource TemplatedParent}}"/>
<TextBlock Grid.Column="1"
TextAlignment="Left"
Foreground="Black">
<ContentPresenter/>
</TextBlock> …Run Code Online (Sandbox Code Playgroud)