-1

默认 SplitButton 可以正常工作,但是当我尝试使用它时,会出现控件模板问题。如果我尝试通过反射(使用 ConstructorInfo)获取控制模板,我会得到 SplitButton 的空控制模板。如果我尝试在 XAML 设计器中“编辑模板副本”,我得到的副本不起作用(例如 ItemsSource 未绑定到 SplitButton 的 ListBox 中的元素,因为它始终为空)。我的 MahApps Metro 版本是 1.4.3.0

这是我尝试获取SplitButton的控制模板的方法:

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);
4

2 回答 2

1

默认ControlTemplate在 GitHub 上可用:https ://github.com/MahApps/MahApps.Metro/blob/336f7dfc4bda2d0eba8aa270737ca3c11d45128c/src/MahApps.Metro/MahApps.Metro/Themes/SplitButton.xaml

MahApps.Metro是开源的,因此您可以根据需要下载源代码。

于 2017-08-30T10:07:40.253 回答
0

将 MahApps Metro 更新到 1.5.0 后,SplitButton 可以与提供的控制模板一起正常工作...

于 2017-08-30T13:04:44.187 回答