积极答复者
我该在哪里方式样式文件,然后怎么引用了

问题
-
我该在哪里方式样式文件,然后怎么引用了?~
public class MyButton2 : Button
{
public MyButton2()
{
//ButtonStyle3
//这个样式文件对于这个Class,应该放在在哪里,该怎么引用了
}public event RoutedEventHandler MyClick;
public override void OnApplyTemplate()
{base.OnApplyTemplate();
Button btn = (Button)GetTemplateChild("button");
btn.Click += new RoutedEventHandler(btn_Click);}
void btn_Click(object sender, RoutedEventArgs e)
{
if (MyClick != null)
{
MyClick(this, new RoutedEventArgs());
}
}
}
原因是 我每次调用这样来使用该类
<Grid x:Name="LayoutRoot">
<my:MyButton2 x:Name="mybtn2" Style="{StaticResource ButtonStyle3}" MyClick="mybtn2_MyClick" ></my:MyButton2>
</Grid>
这样显然不好. 我想 ButtonStyle3 与 MyButton2这个类相对独立起来.
/////
我想在一个控件里增加一些控件样式 再添加一些功能,可是又不想完全自定义一个BUTTON, 结果就这样了.
如果这不符合常规,,以后我看自定控件去吧. 谢谢了.
答案
-
你好,
样式文件放在控件所在的assembly里. 请参考CSSL3CustomControl项目.改项目描述了如何写一个自定义控件:
http://cfx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33087
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us.- 已标记为答案 Jackie White 2009年9月26日 0:51
全部回复
-
你好,
样式文件放在控件所在的assembly里. 请参考CSSL3CustomControl项目.改项目描述了如何写一个自定义控件:
http://cfx.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33087
Please remember to mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework http://cfx.codeplex.com/! If you have any feedback, please tell us.- 已标记为答案 Jackie White 2009年9月26日 0:51