【问题标题】:MahApps:Metro SplitButton Control TemplateMahApps:Metro SplitButton 控件模板
【发布时间】:2017-08-30 09:36:17
【问题描述】:

默认拆分按钮可以正常工作,但是当我尝试使用它时,会出现控件模板问题。 如果我尝试通过反射(使用 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);

【问题讨论】:

    标签: wpf controltemplate mahapps.metro split-button


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的信息,但我已经从 MahApps 演示应用程序 (ButtonsExample) 中获得了相同的源代码。但是,我使用此控件模板遇到的问题是它无法将 ClipBorder 识别为可用参考(可能是由于版本 1.4.3.0?)
    • 那你为什么不把 ClipBorder 换成 Border 呢?
    • ...您为什么不投票而不是提供自己的有用答案呢?当然默认模板有效。
    【解决方案2】:

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

    【讨论】:

    • 默认模板即使在 1.4.3 版本中也能正常工作
    猜你喜欢
    • 2010-11-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-12
    • 2011-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多