微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Silverlight给按钮添加图片问题

图片作背景,然后显示文字

1
2
3
4
5
6
7
8
  < Button  Height = "60"  Width "68" >   
   Button.Content >   
Grid >   
     Image  Source "image/add.png"  Grid.Row "0" ></ Image >   
TextBlock  Text "Add"  "1"  VerticalAlignment "Center"  TextBlock >   
</ >   
>   
Button
只是没有再分为两行,而是将图片作为背景放在后面,文字放在背景图上。

后台代码的实现方式(c#):供参考

C# code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
            Button btn1 =  new  Button();
             //设置背景图片
             Image myImage =  Image();
myImage.Stretch = Stretch.UniformToFill;
BitmapImage imageSource =  BitmapImage( Uri( "/sl_controls;component/images/cry.jpg" , UriKind.Relative));
myImage.source = imageSource;
//myImage.SetValue(Grid.RowProperty, 0);//如果你要分行或列的话,这样把控件放到相应的位置
 
//设置按钮显示文本
TextBlock myTextBlock =  TextBlock();
myTextBlock.VerticalAlignment = VerticalAlignment.Center;
myTextBlock.HorizontalAlignment = HorizontalAlignment.Center;
myTextBlock.Text =  "Cry" ;
//myTextBlock.SetValue(Grid.RowProperty, 0);//如果你要分行或列的话,这样把控件放到相应的位置
 
Grid myGrid =  Grid();
//myGrid.RowDeFinitions.Add(new RowDeFinition());//用类似语法为grid添加行或列
myGrid.Width = 100;
myGrid.Height = 50;
myGrid.Children.Add(myImage);
myGrid.Children.Add(myTextBlock);
 
btn1.Content = myGrid;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐