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,1,2,3);      

	TempButton.VerticalAlignment = VerticalAlignment.Center;
	TempButton.HorizontalAlignment = HorizontalAlignment.Right;  

	 //URL
	(TempButton.Background as ImageBrush).ImageSource = new BitmapImage(new Uri(“图片路径”), UriKind.Absolute));

	Wrappanel.Children.Add(TempButton);

猜你喜欢

转载自blog.csdn.net/qq_43307934/article/details/107180678