默認SplitButton工作正常,但當我嘗試使用它的控制模板問題出現時。 如果我嘗試使用反射獲得控制模板(使用ConstructorInfo),我得到SplitButton的空控制模板。如果我嘗試在XAML Designer中「編輯模板副本」,則會得到不起作用的副本(例如,ItemsSource不會綁定到SplitButton的ListBox中的元素,因爲它始終爲空)。 我MahApps地鐵的版本是1.4.3.0MahApps:地鐵SplitButton控制模板
這裏是我試圖讓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);
感謝您的信息,但我已經得到了來自MahApps演示應用程序(ButtonsExample)相同的源。然而,我得到這個控制模板的問題是,它不認可ClipBorder作爲可用的參考(可能是由於版本1.4.3.0?) – VladacusB
那麼,爲什麼你不用邊界替換ClipBorder? – mm8
......爲什麼不投票給你有用的答案,而不是提供你自己的答案?當然,默認模板的作品。 – mm8