-1

Default SplitButton works ok, but when I try to work with it's control template issues arise. If I try to get Control Template with reflection (with ConstructorInfo) I get empty Control Template for SplitButton. If I try to 'Edit Template copy' in XAML Designer, I get copy which does not work (like ItemsSource does not bind to elements in ListBox of SplitButton as it is always empty). My version of MahApps Metro is 1.4.3.0

Here is how I try to get Control Template of 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);
VladacusB
  • 844
  • 1
  • 7
  • 24

2 Answers2

1

The default ControlTemplate is available on GitHub: https://github.com/MahApps/MahApps.Metro/blob/336f7dfc4bda2d0eba8aa270737ca3c11d45128c/src/MahApps.Metro/MahApps.Metro/Themes/SplitButton.xaml

MahApps.Metro is open source so you can download the source code if you want to.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thanks for info, but I already got the same source from MahApps demo application (ButtonsExample). However issue I got with this control template is that it does not recognize ClipBorder as available reference (maybe due to version 1.4.3.0?) – VladacusB Aug 30 '17 at 10:47
  • So why don't you replace the ClipBorder with a Border? – mm8 Aug 30 '17 at 10:50
0

After updating MahApps Metro to 1.5.0 SplitButton works fine with provided Control Templates...

VladacusB
  • 844
  • 1
  • 7
  • 24