关于使用WPF模板为按钮添加样式 WPF 模板 样式 动态创建WPF模板样式动态创建 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你应该先打印.net类库中标准Button的Style看看。你所谓的“模板”与 wpf 的概念关系不大。你要想吃鱼,最起码先要见过鱼,知道鱼有几个头。 自定义一个控件类继承Button,给它添加一个图片的依赖属性,然后在模板里面对这个依赖属性进行绑定 自己打造各种按钮 private void Frm_Main_Load(object sender, EventArgs e) { btn_One.Image = //设置按钮上的图像 global::MenuVestige.Properties.Resources.picture; btn_Tow.ForeColor = Color.Red;//设置按钮前景色为红色 btn_Three.FlatStyle = FlatStyle.Flat;//设置按钮以平面显示 btn_Three.ForeColor = Color.Blue;//设置按钮前景色为蓝色 btn_Four.ForeColor = Color.Green;//设置按钮前景色为绿色 btn_Four.FlatStyle = FlatStyle.Popup;//得到焦点后按钮为三维样式 btn_Five.FlatStyle = FlatStyle.Standard;//设置按钮以三维样式显示 btn_six.FlatStyle = FlatStyle.System;//按钮外观由操作系统决定 btn_six.Font = new Font("隶书", 20);//设置按钮文字字体 } 正解!!!样式不能满足楼主的要求,只能自定义模板.正解。附代码一份, public class ImageButton : Button { public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageButton)); public ImageSource ImageSource { get { return (ImageSource)GetValue(ImageSourceProperty); } set { SetValue(ImageSourceProperty, value); } }} 麻烦大家发下C#让winform全屏运行的代码 Resources.resx里面的文件被删除了怎么办 .Net如何给其他软件加壳,以达到自己想要的方式 网站快捷方式怎么做出来的 哪些是C#内置的数据结构 问个DataGridView的问题 如何用C#写dll组件,请给出个例子好么? QQ群:2850156(C#.WinForm)欢迎高手光临指教 ~~~急~~~让客户逼的快要上梁山了,请教:放大、缩小问题!!! 请教高手--DataGrid问题 c# 图片上传 C# vs2012 使用oracleclient连不上数据库,显示用户名密码不对。
private void Frm_Main_Load(object sender, EventArgs e)
{
btn_One.Image = //设置按钮上的图像
global::MenuVestige.Properties.Resources.picture;
btn_Tow.ForeColor = Color.Red;//设置按钮前景色为红色
btn_Three.FlatStyle = FlatStyle.Flat;//设置按钮以平面显示
btn_Three.ForeColor = Color.Blue;//设置按钮前景色为蓝色
btn_Four.ForeColor = Color.Green;//设置按钮前景色为绿色
btn_Four.FlatStyle = FlatStyle.Popup;//得到焦点后按钮为三维样式
btn_Five.FlatStyle = FlatStyle.Standard;//设置按钮以三维样式显示
btn_six.FlatStyle = FlatStyle.System;//按钮外观由操作系统决定
btn_six.Font = new Font("隶书", 20);//设置按钮文字字体
}
样式不能满足楼主的要求,只能自定义模板.
正解。附代码一份, public class ImageButton : Button
{
public static readonly DependencyProperty ImageSourceProperty = DependencyProperty.Register("ImageSource", typeof(ImageSource), typeof(ImageButton)); public ImageSource ImageSource
{
get { return (ImageSource)GetValue(ImageSourceProperty); }
set { SetValue(ImageSourceProperty, value); }
}
}