C#自定义按钮如何在其形状更改后设置内容属性 [英] C# custom button how to set content property after its shape changed

查看:405
本文介绍了C#自定义按钮如何在其形状更改后设置内容属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了一个椭圆形状的按钮控件,但是如何设置其内容属性。

 <   window.resources  >  

< Setter 属性 = 模板 >
< span class =code-keyword>< Setter.Value >
< ControlTemplate TargetType = {x:Type Button} <跨越式s =code-keyword>>
< 网格 < span class =code-keyword>>
< Ellipse x:名称 = 形状 填充 = #FF484874 Horizo​​ntalAlignment = 中心 高度 = 39 Stro ke = 黑色 VerticalAlignment = 中心 宽度 = 46 / >
< TextBlock x :名称 = 名称 文本 = {Binding Content,ElementName = button} VerticalAlignment = center Horizo​​ntalAlignment = 中心 前景 = #FF14F309 / >
< / grid >
< ControlTemplate.Triggers >
< 触发器 属性 = IsMouseOver = true >
< Setter TargetName = 形状 属性 = 不透明度 = 0.5 / >
< / trigger >
< / controltemplate.Triggers >
< / controltemplate >
< / setter.Value >
< / setter >





我的尝试:



我试图在controltemplate中添加一个文本块来显示文本,但是这会使它无法重复使用。如何在这个cus上显示一个文本tom button。

解决方案

最近有一个问题就像这个问题一样:如何使我的按钮网格适合我在WPF-XAML中的六边形图像 [ ^ ]

I made a button control with a ellipse shape,but how to set its Content property next.

<window.resources>
        
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type Button}">
                        <Grid>
                            <Ellipse x:Name="shape" Fill="#FF484874" HorizontalAlignment="Center" Height="39" Stroke="Black" VerticalAlignment="Center" Width="46"/>
                            <TextBlock x:Name="name"  Text="{Binding Content,ElementName=button}" VerticalAlignment="center" HorizontalAlignment="Center" Foreground="#FF14F309"/>
                        </grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="shape" Property="Opacity" Value="0.5"/>
                            </trigger>
                        </controltemplate.Triggers>
                    </controltemplate>
                </setter.Value>
            </setter>



What I have tried:

I have tried to add a textblock in controltemplate to show the text,but this will make it can't be reused.How to show a text on this custom button.

解决方案

There was a question just like this one asked recently: How to make my button grid fit my hexagon image in WPF-XAML[^]


这篇关于C#自定义按钮如何在其形状更改后设置内容属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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