WPF_后台设置控件的颜色字体

Button TempButton = new Button();
TempButton.Tag = “标记内容”;
//设置宽高
TempButton.Height = 30;
TempButton.Width = 100;
//设置样式
TempButton.Style = this.FindResource("ButtonStyle_blue") as Style;
                                   
//颜色
//      背景色
TempButton.Background = new SolidColorBrush(Colors.Black);
//前景色(字体颜色)
TempButton.Foreground = new SolidColorBrush(Color.FromArgb(0xff, 0x6e, 0x6e, 0x6e));
 //字体
TempButton.FontFamily = new FontFamily("Microsoft YaHei");
//字体大小
TempButton.FontSize = 13;
//字体加粗
TempButton.FontWeight = FontWeights.Normal; 
 //布局
//    外边距
TempButton.Margin = new Thickness(0);   
//    垂直居中
TempButton.VerticalAlignment = VerticalAlignment.Center;
//    水平靠右
TempButton.HorizontalAlignment = HorizontalAlignment.Right;  
//URL
(TempButton.Background as ImageBrush).ImageSource = new BitmapImage(new Uri(“图片路径”), UriKind.Absolute));
Wrappanel.Children.Add(TempButton);

 

posted @ 2022-06-05 17:02  驼七  阅读(120)  评论(0)    收藏  举报