自定义按钮 [英] Custom Button

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

问题描述

我需要有关自定义按钮的帮助.

我已使用模板自定义表面按钮的形状
但是之后,我无法更改按钮的背景颜色.
这是需要的

有人可以帮我吗?

这是我的代码:

I need help with the custom buttons.

I''ve used a template to customize the shape of my surfacebutton
But after that I couldn''t change the background color of the button.
which is needed

Can someone help me?

this is my code:

<ControlTemplate
      x:Key="dorpje">
      <Grid>
        <Ellipse x:Name="Ell" Width="15" Height="15" Stroke="Black" Opacity="0.4">
          <Ellipse.BitmapEffect>
            <DropShadowBitmapEffect Color="Black" ShadowDepth="6" Opacity="0.7"/>
          </Ellipse.BitmapEffect>
        </Ellipse>
     </Grid>
</ControlTemplate>

推荐答案


由于您正在为按钮定义控件模板,因此它将覆盖默认模板.现在,您的Button在网格中具有一个椭圆形.要更改背景色,请绑定Grid的背景或使用templatebinding绑定椭圆的fill属性.例如:

Hi,
Since you are defining the control template for the button, it overrides the default template.Now your Button has an ellipse inside a grid.To change the background color bind the background of Grid or bind the fill property of ellipse using templatebinding . eg:

<ControlTemplate      x:Key="dorpje">
      <Grid Background="{TemplateBinding Background}">
        <Ellipse x:Name="Ell" Width="15" Height="15" Stroke="Black" Opacity="0.4">
          <Ellipse.BitmapEffect>
            <DropShadowBitmapEffect Color="Black" ShadowDepth="6" Opacity="0.7"/>
          </Ellipse.BitmapEffect>
        </Ellipse>
     </Grid>
</ControlTemplate>







OR

<ControlTemplate      x:Key="dorpje">
      <Grid>
        <Ellipse x:Name="Ell" Fill="{TemplateBinding Background}" Width="15" Height="15" Stroke="Black" Opacity="0.4">
          <Ellipse.BitmapEffect>
            <DropShadowBitmapEffect Color="Black" ShadowDepth="6" Opacity="0.7"/>
          </Ellipse.BitmapEffect>
        </Ellipse>
     </Grid>
</ControlTemplate>



再加一点.如果必须设置按钮的宽度"和高度",还可以使用"templateBinding"设置为椭圆/网格的宽度和高度".



One more Point. If you have to set the Width and Height of the button , Using templateBinding to Width and Height of Ellipse/Grid also.

<ControlTemplate   TargetType="{x:Type Button}"   x:Key="dorpje">
           <Grid Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
               <Ellipse x:Name="Ell" Fill="{TemplateBinding Background}"  Stroke="Black" Opacity="0.4">
                   <Ellipse.BitmapEffect>
                       <DropShadowBitmapEffect Color="Black" ShadowDepth="6" Opacity="0.7"/>
                   </Ellipse.BitmapEffect>
               </Ellipse>
           </Grid>
       </ControlTemplate>


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

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