首页 新闻 会员 周边

关于WPF在后台动态创建按钮的问题

0
悬赏园豆:20 [已关闭问题] 关闭于 2018-06-21 11:43

请问要怎么在后台动态创建出如图的按钮?

要怎么在button里面添加rectangle呢?

rectangle的fill怎么写?

谢谢

WPF
问题补充:
VisualBrush vb = new VisualBrush
{
    Stretch = Stretch.Fill,
    Visual = this.FindResource("appbar_edit_minus") as Visual
};

RelativeSource relativeSource = new RelativeSource
{
     Mode = RelativeSourceMode.FindAncestor,
     AncestorType = typeof(Button)
};            

Rectangle rectangle = new Rectangle
{
     Width = 14,
     Height = 14,
};
rectangle.SetBinding(Rectangle.FillProperty, new Binding("Foreground")
{
     RelativeSource = relativeSource
});

rectangle.OpacityMask = vb;

     Style btn_style = (Style)this.FindResource("MetroFlatButton");
     Button btn = new Button
{
     Name = $"sub_jbxx{jbxxnum}",
     ToolTip = "删除本行",
     IsEnabled = true,
     VerticalAlignment = VerticalAlignment.Center,
     Background = Brushes.Transparent,
     Style = btn_style
};


请问要怎么在button里面放入Rectangle?

bgh的主页 bgh | 初学一级 | 园豆:45
提问于:2018-06-21 10:21
< >
分享
所有回答(1)
0

button.content试过没?

众生少两千 | 园豆:1 (初学一级) | 2018-07-30 13:12

其实还有个方法也可以试试,就是设置一个button的模板样式,然后再后台cs文件里面设置它的Button.Template = this.Resources["ButtonTemplate"] as ControlTemplate,你试试

支持(0) 反对(0) 众生少两千 | 园豆:1 (初学一级) | 2018-07-30 13:14

就是用button解决了。。

 

支持(0) 反对(0) bgh | 园豆:45 (初学一级) | 2018-07-30 13:36

@bgh: 啥意思?你弄好了?如果弄好了,大佬,帮我看个问题吧。。

https://q.cnblogs.com/q/108418/   谢了。。。。

支持(0) 反对(0) 众生少两千 | 园豆:1 (初学一级) | 2018-07-30 13:37

@众生少两千: 我的意思是用button.content解决了,我不是大佬,wpf我也才学···

支持(0) 反对(0) bgh | 园豆:45 (初学一级) | 2018-07-30 13:39

@bgh: 好吧。解决了就好。

支持(0) 反对(0) 众生少两千 | 园豆:1 (初学一级) | 2018-07-30 13:40
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册