如何从代码中更改矩形填充 [英] How Do I change Rectangle Fill from code

查看:78
本文介绍了如何从代码中更改矩形填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个矩形灰色图像的按钮。我想要的是,当我点击它时,按钮变为蓝色图像。



我该怎么做?



如有任何建议,我们将不胜感激





Hi,

I have a button with a gray image in a rectangle. What I want, is that when I click on it, the button change to a blue image.

How Do I do That?

Any suggestion will be appreciated


<Button x:Name="botonAlumnos" DockPanel.Dock="Top" Click="botonAlumnos_Click">
   <Button.Template>
        <ControlTemplate>
           <Rectangle x:Name="rect1" Height="125" Width="125">
              <Rectangle.Fill>
                 <ImageBrush ImageSource="{DynamicResource _Alumnos}"/>
              </Rectangle.Fill>
           </Rectangle>
        </ControlTemplate>
   </Button.Template>
</Button>





___________________ _____________



现在我在网上创建了这个





________________________________

Now I founded this on the web

private void botonAlumnos_Click(object sender, RoutedEventArgs e)
{
 var rect1 = botonAlumnos.Template.FindName("rectAlumnos", botonAlumnos) as Rectangle;
 rect1.Fill = Brushes.White;
}





使用此代码,Rectangle变为白色。我想要的是填充图片。



With this code the Rectangle turns White. What I want is fill it with a picture.

推荐答案

请参阅我对该问题的评论。请参阅: http:// msdn .microsoft.com / zh-CN / library / system.windows.shapes.shape.fill%28v = vs.110%29.aspx [ ^ ]。



请注意,您已经在XAML中使用过它。 XAML中的每个元素和属性都记录在MSDN中。



-SA
Please see my comment to the question. Please see: http://msdn.microsoft.com/en-us/library/system.windows.shapes.shape.fill%28v=vs.110%29.aspx[^].

Note that you already had it in XAML. And every element and attribute in XAML is documented in MSDN.

—SA


这篇关于如何从代码中更改矩形填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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