WPF组合框与图标 [英] WPF Combo Box With Icon

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

问题描述





我是WPF的新手。我正在尝试了解wpf控件模板。我的问题是,如何制作带图标的自定义组合框。不同的组合框的图标会有所不同。因此图标图像源必须是可更改的。这是一个带图标的示例组合框。 http://i49.tinypic.com/dq40hf.png [ ^ ]



有什么想法吗?



谢谢。

解决方案

您使用的是哪种表格?



如果你能说清楚,那就很容易解决你的疑问。



谢谢


谢谢大家,为你的答案。但我通过编辑组合框控件模板解决了这个问题。



组合框控件模板由三部分组成。



一个是ToggleButton,第二个是ComboBoxTextBox和ComboBox本身。要向组合框添加图标,您必须编辑ToggleButton控件模板。



在Microsoft站点上,您可以找到组合框控件模板。 http://msdn.microsoft.com/en -us / library / ms752094%28v = vs.85%29.aspx [ ^ ]



这是一个带图标的切换按钮示例。 />


 <   controltemplate     x:key   =  ComboBoxToggleButtonIcon    targettype   =  ToggleButton    xmlns:x   = #unknown >  
< grid >
< grid.columndefinitions >
< columndefinition < span class =code-attribute> width = 0 / > ;
< columndefinition / >
< ; /grid.columndefinitions >
< border x:name = 边框 grid。 columnspan = 2 cornerradius = 2 borderthickness = 1 >
< border.background >
< imagebrush imagesource = / images / icon.png stretch = / >
< / border.background >
< / border >
< border grid.column = 0 cornerradius = 0 ,0,0,0 margin = 0 background = 透明 borderbrush = 透明 borderthickness = 0 ,0,0,0 / >
< path x:name = 箭头 grid.column = 1 fill = #444 horizo​​ntalalignment = verticalalignment = 中心 margin = 0,0,10,0 data = M 0 0 L 4 4 L 8 0 Z / >
< / grid >
< controltemplate.triggers >
< 触发器 property = ToggleButton .IsMouseOver value = true >
...
< / trigger >
< 触发器 property = ToggleButton .IsChecked value = true >
...
< / trigger >
< 触发器 property = IsEnabled value = False >
...
< / trigger > ;
< / controltemplate.triggers >
< / controltemplate >





您可以在组合框控件模板中使用此切换按钮的名称。


Hi,

I am new to WPF. I am trying to learn about wpf control templates. My question, how a custom combo box with icon can be made. Icon will be different for different combo boxes. So icon image source must be changeable. Here is an example combo box with icon. http://i49.tinypic.com/dq40hf.png[^]

Any ideas ?

Thank you.

解决方案

Which form are you using?

If you can tell that then, It would be easy to solve your query.

Thanks


Thank you all, for your answers. But i solved this with editing combo box control template.

Combo Box Control Template consist of three parts.

One is ToggleButton, second ComboBoxTextBox and ComboBox itself. To add an icon to combobox you must edit the ToggleButton control template.

At Microsoft site you can find the combo box control template. http://msdn.microsoft.com/en-us/library/ms752094%28v=vs.85%29.aspx[^]

Here is an toggle button example with an icon.

<controltemplate x:key="ComboBoxToggleButtonIcon" targettype="ToggleButton" xmlns:x="#unknown">
        <grid>
            <grid.columndefinitions>
                <columndefinition width="0" />
                <columndefinition />
            </grid.columndefinitions>
            <border x:name="Border" grid.columnspan="2" cornerradius="2" borderthickness="1">
                <border.background>
                    <imagebrush imagesource="/images/icon.png" stretch="None" />
                </border.background>
            </border>
            <border grid.column="0" cornerradius="0,0,0,0" margin="0" background="Transparent" borderbrush="Transparent" borderthickness="0,0,0,0" />
            <path x:name="Arrow" grid.column="1" fill="#444" horizontalalignment="Right" verticalalignment="Center" margin="0,0,10,0" data="M 0 0 L 4 4 L 8 0 Z" />
        </grid>
        <controltemplate.triggers>
            <trigger property="ToggleButton.IsMouseOver" value="true">
                ...
            </trigger>
            <trigger property="ToggleButton.IsChecked" value="true">
                ...
            </trigger>
            <trigger property="IsEnabled" value="False">
                ...
            </trigger>
        </controltemplate.triggers>
    </controltemplate>



You can use this toggle button in your combo box control template with name.


这篇关于WPF组合框与图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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