我正在开发一个具有自定义ComboBox的应用程序。
ComboBox的外观应该是这样的。
我已将ComboBox的ControlTemplate修改为如上所示。
问题是: 当我继续按下禁用的重复按钮时,也禁用了Up RepeatButton(以编程方式禁用)项目被选中。
我使用的控件模板是:
<Setter
Property ="SnapsToDevicePixels"
Value ="True"
/>
<Setter
Property ="FocusVisualStyle"
Value ="{DynamicResource ComboFocusVisualStyle}"
/>
<Setter
Property ="Foreground"
Value ="Black"
/>
<Setter
Property ="Template"
>
<Setter.Value>
<ControlTemplate
TargetType ="{x:Type ComboBox}"
>
<Grid>
<Border
CornerRadius ="3"
BorderThickness ="0,0,0,.7"
BorderBrush ="WhiteSmoke"
>
<Border
Name ="brd1"
CornerRadius ="3"
BorderBrush ="{StaticResource ComboBorderBrush}"
BorderThickness ="1,1,1,1"
Background ="{TemplateBinding Background}"
ToolTip ="{TemplateBinding SelectionBoxItem, Converter={StaticResource ToolTipConverter}, ConverterParameter=PrinterInfoCol}"
>
<Grid>
<ContentPresenter
x:Name ="ContentSite"
HorizontalAlignment ="Left"
VerticalAlignment ="Center"
IsHitTestVisible ="False"
>
<ContentPresenter.Content>
<Grid
Width ="180"
>
<Grid.ColumnDefinitions>
<ColumnDefinition
Width ="180"
/>
</Grid.ColumnDefinitions>
<TextBlock
Grid.Column ="0"
Margin ="10,0,0,0"
Text ="{TemplateBinding SelectionBoxItem, Converter={StaticResource TextConverter}}"
TextTrimming ="CharacterEllipsis"
VerticalAlignment ="Center"
Foreground ="Black"
/>
</Grid>
</ContentPresenter.Content>
</ContentPresenter>
<!-- The ToggleButton is databound to the ComboBox itself to toggle IsDropDownOpen -->
<ToggleButton
x:Name ="ToggleButton"
Template ="{DynamicResource ComboBoxToggleButton}"
Focusable ="false"
IsChecked ="{Binding Path=IsDropDownOpen,
Mode =TwoWay,
RelativeSource ={RelativeSource TemplatedParent}}"
ClickMode ="Press"
Margin ="16,5,2,2"
/>
</Grid>
</Border>
</Border>
<!-- The Popup shows the list of items in the
ComboBox. IsOpen is databound to IsDropDownOpen
which is toggled via the ComboBoxToggleButton -->
<Popup
x:Name ="PART_popup"
IsOpen ="{TemplateBinding IsDropDownOpen}"
ScrollViewer.VerticalScrollBarVisibility ="Auto"
Placement ="Bottom"
Focusable ="False"
MinWidth ="{Binding ElementName=brd1, Path=ActualWidth}"
AllowsTransparency ="True"
PopupAnimation ="None"
MaxWidth ="325"
>
<dropShadow:SystemDropShadowChrome
Visibility ="Visible"
Margin ="3"
>
<Grid
x:Name ="DropDown"
SnapsToDevicePixels ="True"
Margin ="0,-1,0,0"
>
<Grid.RowDefinitions>
<RowDefinition
Height="18"
/>
<RowDefinition
Height="*"
/>
<RowDefinition
Height="18"
/>
</Grid.RowDefinitions>
<Border
x:Name ="DropDownBorder"
Grid.Row="0"
Grid.RowSpan="3"
Background ="{StaticResource dropDownBackground}"
BorderBrush ="{DynamicResource SolidBorderBrush}"
BorderThickness ="1"
/>
<RepeatButton
x:Name ="upRepeatButton"
Grid.Row ="0"
Margin ="1,0"
ClickMode ="Press"
Style ="{DynamicResource ScrollBarLineButton}"
Height ="18"
Content ="M 0 4 L 8 4 L 4 0 Z"
/>
<ScrollViewer
Name ="scrollCombo"
Margin ="1,0,1,0"
Style ="{DynamicResource ComboBoxScrollViewerStyle}"
Grid.Row ="1"
SnapsToDevicePixels ="True"
HorizontalScrollBarVisibility ="Hidden"
VerticalScrollBarVisibility ="Hidden"
CanContentScroll ="False"
HorizontalAlignment ="Stretch"
Focusable ="False"
>
<ItemsPresenter
Margin="0,18"
/>
</ScrollViewer>
<RepeatButton
x:Name ="downRepeatButton"
Grid.Row ="2"
Margin ="1,0"
ClickMode ="Press"
Style ="{StaticResource ScrollBarLineButton}"
Height ="18"
Content ="M 0 0 L 4 4 L 8 0 Z"
/>
</Grid>
</dropShadow:SystemDropShadowChrome>
</Popup>
</Grid>
<ControlTemplate.Triggers>
<!-- This forces the DropDown to have a minimum
size if it is empty -->
<Trigger
Property ="HasItems"
Value ="false"
>
<Setter
Property ="MinHeight"
Value ="95"
TargetName ="DropDownBorder"
/>
</Trigger>
<Trigger
Property ="IsGrouping"
Value ="True"
>
<Setter
Property ="ScrollViewer.CanContentScroll"
Value ="false"
/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
有关于此的任何想法吗?