2017-08-30 87 views
-2

默認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); 

回答

1

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

MahApps.Metro是開源所以你可以下載源代碼,如果你想。

+0

感謝您的信息,但我已經得到了來自MahApps演示應用程序(ButtonsExample)相同的源。然而,我得到這個控制模板的問題是,它不認可ClipBorder作爲可用的參考(可能是由於版本1.4.3.0?) – VladacusB

+0

那麼,爲什麼你不用邊界替換ClipBorder? – mm8

+0

......爲什麼不投票給你有用的答案,而不是提供你自己的答案?當然,默認模板的作品。 – mm8

0

更新MahApps地鐵到1.5.0後SplitButton正常工作與提供的控件模板...

+0

即使在版本1.4.3中,默認模板也可以正常工作 – jsanalytics