在 WPF 中自定义组合框箭头 [英] customize combo box arrow in WPF

查看:53
本文介绍了在 WPF 中自定义组合框箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想像这样自定义 WPF 组合框箭头位置

I want to customize the WPF Combo Box arrow postion like this

我谷歌了一下.但我无法得到任何正确答案.

I google it. But i could not get any correct answer.

如何自定义组合框箭头?

How can i customize the combo box arrow?

推荐答案

正如@RohitVats 所暗示的,您需要为您的 ComboBox 控件定义一个新的 ControlTemplate.您可以在 MSDN 上的文章使用 ControlTemplate 自定义现有控件的外观.一个好的起点是实现默认的 ControlTemplate,然后根据需要对其进行自定义.您可以在 ComboBox 的默认 ControlTemplaterel="noreferrer">MSDN 上的组合框样式和模板页面.

As @RohitVats has hinted, you will need to define a new ControlTemplate for your ComboBox control. You can find out how to define a new ControlTemplate in the Customizing the Appearance of an Existing Control by Using a ControlTemplate article on MSDN. A good place to start is by implementing the default ControlTemplate and then customising it as you see fit. You can find the default ControlTemplate of the ComboBox in the ComboBox Styles and Templates page on MSDN.

在默认的ControlTemplate 中,您将看到为名为ComboBoxToggleButtonToggleButton 控件定义的ControlTemplate.在那个 ControlTemplate 中,你会发现一个名为 ArrowPath... 那个 是你想要的部分替换:

Inside the default ControlTemplate, you will see a ControlTemplate defined for a ToggleButton control named ComboBoxToggleButton. In that ControlTemplate, you will find a Path named Arrow... that is the part that you want to replace:

<Path x:Name="Arrow"
      Grid.Column="1"
      HorizontalAlignment="Center"
      VerticalAlignment="Center"
      Data="M 0 0 L 4 4 L 8 0 Z" >
    <Path.Fill>
        <SolidColorBrush Color="{DynamicResource GlyphColor}"/>
    </Path.Fill>
</Path>

这篇关于在 WPF 中自定义组合框箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆