请问要怎么在后台动态创建出如图的按钮?
要怎么在button里面添加rectangle呢?
rectangle的fill怎么写?
谢谢
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?
button.content试过没?
其实还有个方法也可以试试,就是设置一个button的模板样式,然后再后台cs文件里面设置它的Button.Template = this.Resources["ButtonTemplate"] as ControlTemplate,你试试
就是用button解决了。。
@bgh: 啥意思?你弄好了?如果弄好了,大佬,帮我看个问题吧。。
https://q.cnblogs.com/q/108418/ 谢了。。。。
@众生少两千: 我的意思是用button.content解决了,我不是大佬,wpf我也才学···
@bgh: 好吧。解决了就好。