如何按钮在WPF中表现w.r.t图像 [英] How button to behave w.r.t image in WPF

查看:54
本文介绍了如何按钮在WPF中表现w.r.t图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望按钮表现为w.r.t图像,因为它是图像的大小。实际上我想显示按钮,因为它是图像提供的。例如,在下面的代码中,我的图像源正在改变,但其他代码是相同的。

I want button to behave w.r.t image as it is size of image.Actually i want to show button as it is of image provided. For example in below code my image source is changing but other code is same.

<Button  x:Name="BtnMin"  Content=""  Click="btnStartStop_Click" Margin="403.956,88.106,316.044,379.656" RenderTransformOrigin="0.5,0.5">
          
            <Button.Template>
                <ControlTemplate>
                    <Grid>
                        <Ellipse>
                            <Ellipse.Fill>
                                <ImageBrush ImageSource="Images/minimize.png"/>
                            </Ellipse.Fill>
                        </Ellipse>
                    </Grid>
                </ControlTemplate>
            </Button.Template>
        </Button>
 <Button  x:Name="btnStartStop"  Content="" Margin="84.851,0,495.149,258.284" VerticalAlignment="Bottom" Click="btnStartStop_Click">
            <Button.Template>
                <ControlTemplate>
                    <Grid>
                        <Ellipse>
                            <Ellipse.Fill>
                                <ImageBrush ImageSource="Images/glossyicon.png"/>
                            </Ellipse.Fill>
                        </Ellipse>
                    </Grid>
                </ControlTemplate>
            </Button.Template>
        </Button>



任何人都可以建议如何创建模板,我会在代码中应用,这样我的代码大小就会减少。


Can any one suggest how to create template where in code I will apply so my code size will reduce.

推荐答案

Hello Vishal,我理解您的关注,针对您的特定问题,您需要为该特定按钮创建样式,并且必须在运行时使用转换器分配值





适合您关注的代码。



http://wpfadv.blogspot.in/2010/03/image-button-control-template.html [< a href =http://wpfadv.blogspot.in/2010/03/image-button-control-template.html\"target =_ blanktitle =New Window> ^ ]





您可能会发现这个过程对于您的两个按钮来说有点冗长,但如果按钮数量相同,那么您可以使用提供的链接方式定义按钮的样式。
Hello Vishal, I Understood your concern, for your specific issue you need to create style for that particular button and had to assign value at runtime of image source using converter


suited code for your concern.

http://wpfadv.blogspot.in/2010/03/image-button-control-template.html[^]


You might find this process bit lengthy for your two button but if you have same thing for number of buttons then you can go with provided link way to define a style for a button.


这篇关于如何按钮在WPF中表现w.r.t图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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