WPF三态图像按钮 [英] WPF TriState Image Button

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

问题描述

有没有人有建立一个三态图像按钮任何指针?

我有以下的,但我真正想要做的是有像多个ImageSource的属性控制< Controls.TristateButton图像=HoverImage =pressedImage =/ >

 <风格的TargetType ={X:类型按钮}>
    < setter属性=模板>
        < Setter.Value>
            <的ControlTemplate的TargetType ={X:类型按钮}>
                < StackPanel的方向=横向>
                    <图像名称=PART_Image来源=路径正常的图像/>
                < / StackPanel的>
                < ControlTemplate.Triggers>
                    <触发属性=IsMouseOverVALUE =真>
                        < setter属性=源值= =的TargetNamePART_Image过的图像路径​​的鼠标/>
                    < /触发>
                    <触发属性=是pressedVALUE =真>
                        < setter属性=源VALUE =路径pressed形象的TargetName =PART_Image/>
                    < /触发>
                < /ControlTemplate.Triggers>
            < /控件模板>
        < /Setter.Value>
    < /二传手>
< /样式和GT;


解决方案

接受的回答这个问题,计算器给出了一个简单的方法来做到这一点:
<一href=\"http://stackoverflow.com/questions/1261908/wpf-how-to-create-image-button-with-template\">http://stackoverflow.com/questions/1261908/wpf-how-to-create-image-button-with-template

您创建属性会触发对IsEnabled和是pressed性能和显示或根据需要隐藏图像。

由于Avanka在他的回答说,你需要创建依赖属性的路径设置为图像。

Does anyone have any pointers for creating a tristate image button?

I have the following but what I really want to do is have a control with multiple ImageSource properties like <Controls.TristateButton Image="" HoverImage="" PressedImage="" />

<Style TargetType="{x:Type Button}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type Button}">
                <StackPanel Orientation="Horizontal" >
                    <Image Name="PART_Image" Source="path to normal image" />
                </StackPanel>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsMouseOver" Value="True">
                        <Setter Property="Source" Value="path to mouse over image" TargetName="PART_Image"/>
                    </Trigger>
                    <Trigger Property="IsPressed" Value="True">
                        <Setter Property="Source" Value="path to pressed image" TargetName="PART_Image"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

解决方案

The accepted answer to this StackOverflow question shows an easy way to do this: http://stackoverflow.com/questions/1261908/wpf-how-to-create-image-button-with-template

You create property triggers on the IsEnabled and IsPressed properties and show or hide the images as needed.

As Avanka noted in his answer, you'll need to create dependency properties to set the paths to the images.

这篇关于WPF三态图像按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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