Wpf MahApps:Metro SplitButton控制模板
默认SplitButton工作正常,但当我尝试使用它的控件模板时,会出现问题。 如果我尝试使用反射(使用ConstructorInfo)获取控件模板,我会为SplitButton获取空控件模板。如果我尝试在XAML设计器中“编辑模板副本”,我会得到不起作用的副本(例如ItemsSource不会绑定到SplitButton列表框中的元素,因为它总是空的)。 我的MahApps Metro版本是1.4.3.0 下面是我如何尝试获取SplitButton的控件模板:Wpf MahApps:Metro SplitButton控制模板,wpf,controltemplate,mahapps.metro,split-button,Wpf,Controltemplate,Mahapps.metro,Split Button,默认SplitButton工作正常,但当我尝试使用它的控件模板时,会出现问题。 如果我尝试使用反射(使用ConstructorInfo)获取控件模板,我会为SplitButton获取空控件模板。如果我尝试在XAML设计器中“编辑模板副本”,我会得到不起作用的副本(例如ItemsSource不会绑定到SplitButton列表框中的元素,因为它总是空的)。 我的MahApps Metro版本是1.4.3.0 下面是我如何尝试获取SplitButton的控件模板: MahApps.Metro.Con
MahApps.Metro.Controls.SplitButton ctl = sender as MahApps.Metro.Controls.SplitButton;
Type type = ctl.GetType();
if (type == null)
return;
// Instantiate the type.
ConstructorInfo info = type.GetConstructor(System.Type.EmptyTypes);
Control control = (Control)info.Invoke(null);
// Get the template.
ControlTemplate template = control.Template;
// Get the XAML for the template.
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
StringBuilder sb = new StringBuilder();
XmlWriter writer = XmlWriter.Create(sb, settings);
XamlWriter.Save(template, writer);
GitHub上提供了默认的
ControlTemplate
:
MahApps.Metro
是开源的,因此如果您愿意,可以下载源代码。将MahApps Metro更新为1.5.0后,SplitButton可以与提供的控制模板配合使用……感谢您提供的信息,但我已经从MahApps演示应用程序(ButtonsExample)获得了相同的源代码。然而,这个控制模板的问题是它不能识别剪贴簿作为可用的参考(可能是因为版本1.4.3.0)。所以为什么不用边框替换剪贴簿?…为什么不投票支持有用的答案,而不是提供自己的答案?当然,默认模板可以工作。即使在版本1.4.3中,默认模板也可以正常工作