none
如何让ComboBox 只有在点击三角形时才显示下拉列表,点击其它位置时调用其它函数 RRS feed

  • 问题

  • 如何实现图中效果:

    1. 只有点击小三角形时才弹出下拉列表

    2. 单击除小三角形之外其余的位置,调用不同的函数

    例如:一开始默认选择的是Line,此时单击Line,会跳出画直线的界面;通过点击小三角形并选择Ellipse之后,ComboBox选中图标修改为椭圆,如果单击Ellipse,会跳出画椭圆的界面。

    <audio controls="controls" style="display:none;"></audio>

    2018年11月3日 10:18

答案

  • Hi  ShannonZhou,

    你可以参考WPF 中使用Ribbon控件。Ribbon控件的ibbonSplitButton菜单项可以小三角单独触发事件。

              <ribbon:RibbonGroup x:Name="ClipboardGroup" Header="Clipboard">
                        <ribbon:RibbonMenuButton LargeImageSource="image\Icon.ico" Label="Paste" KeyTip="V">
                            <ribbon:RibbonMenuItem ImageSource="image\Icon.ico" Header="Keep Text Only" KeyTip="T"/>
                            <ribbon:RibbonMenuItem ImageSource="image\Icon.ico" Header="Paste Special..." KeyTip="S"/>
                        </ribbon:RibbonMenuButton>
                        <ribbon:RibbonButton SmallImageSource="image\Icon.ico" Label="Cut" KeyTip="X" />
                        <ribbon:RibbonButton SmallImageSource="image\Icon.ico" Label="Copy" KeyTip="C" />
                        <ribbon:RibbonButton SmallImageSource="image\Icon.ico" Label="Format Painter" KeyTip="FP" />
                        <ribbon:RibbonSplitButton x:Name ="Undo22" SmallImageSource="image\Icon.ico" Click="Undo22_Click" >
                            <ribbon:RibbonSplitMenuItem Header="test  action #1" Click="RibbonSplitMenuItem_Click" />
                            <ribbon:RibbonSplitMenuItem Header="test  action #2" />
                            <ribbon:RibbonSplitMenuItem Header="test  action #3" />
                        </ribbon:RibbonSplitButton>
                    </ribbon:RibbonGroup>
    


    下面链接供你参考:

    Ribbon (WPF)


    WPF中Ribbon控件的使用 


    Best Regards,

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年11月5日 2:34
    版主

全部回复

  • 一个简单的做法,用一个组合控件的思路,将Combobox拆分为两个控件,一个Combobox,一个Picture(三角),

    1. Combobox点击不注册下拉事件

    2. Picture注册一个点击,下拉Combobox的事件。

    希望能帮助到你。


    ericzhou

    2018年11月4日 0:36
  • Hi  ShannonZhou,

    你可以参考WPF 中使用Ribbon控件。Ribbon控件的ibbonSplitButton菜单项可以小三角单独触发事件。

              <ribbon:RibbonGroup x:Name="ClipboardGroup" Header="Clipboard">
                        <ribbon:RibbonMenuButton LargeImageSource="image\Icon.ico" Label="Paste" KeyTip="V">
                            <ribbon:RibbonMenuItem ImageSource="image\Icon.ico" Header="Keep Text Only" KeyTip="T"/>
                            <ribbon:RibbonMenuItem ImageSource="image\Icon.ico" Header="Paste Special..." KeyTip="S"/>
                        </ribbon:RibbonMenuButton>
                        <ribbon:RibbonButton SmallImageSource="image\Icon.ico" Label="Cut" KeyTip="X" />
                        <ribbon:RibbonButton SmallImageSource="image\Icon.ico" Label="Copy" KeyTip="C" />
                        <ribbon:RibbonButton SmallImageSource="image\Icon.ico" Label="Format Painter" KeyTip="FP" />
                        <ribbon:RibbonSplitButton x:Name ="Undo22" SmallImageSource="image\Icon.ico" Click="Undo22_Click" >
                            <ribbon:RibbonSplitMenuItem Header="test  action #1" Click="RibbonSplitMenuItem_Click" />
                            <ribbon:RibbonSplitMenuItem Header="test  action #2" />
                            <ribbon:RibbonSplitMenuItem Header="test  action #3" />
                        </ribbon:RibbonSplitButton>
                    </ribbon:RibbonGroup>
    


    下面链接供你参考:

    Ribbon (WPF)


    WPF中Ribbon控件的使用 


    Best Regards,

    Yong Lu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年11月5日 2:34
    版主
  • 那单击Combobox选中项的位置,这个事件呢?<audio controls="controls" style="display:none;"></audio>
    2018年11月6日 0:57

  • Hi   ShannonZhou,

    ericzhou 建议的是一个思路,你完全可以不使用Combobox来组合,可以选择其他显示的控件,加一个显示下拉箭头的控件。下拉箭头的控件触发下拉选项,选择后显示在控件上。 点击显示选项的控件后触发你想要的事件。 

    请尝试,然后选择最优的组合方式。

    如果不想组合控件,上面介绍的Ribbon控件的ibbonSplitButton菜单项也是一个不错的选项。


    Best Regards,

    Yong Lu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年11月6日 1:46
    版主