WPF后台设置颜色字体等

Posted 程序猿kid

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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);

以上是关于WPF后台设置颜色字体等的主要内容,如果未能解决你的问题,请参考以下文章