Posted 17 years ago
by dmelinosky
Anyone ever try to dynamically load a DataTemplate for a RibbonGallery? I can dynamically create the template and load it with XamlReader, but as soon as I try to reference the Actipro Ribbon Common Dictionary, I get an exception.
Here's some codeAn exception is thrown when I get to the XamlReader.Load method. Anyone ever try anything similar?
Here's some code
XElement element = new XElement("DataTemplate",
new XElement("Border",
new XAttribute("Width", "75"),
new XAttribute("BorderThickness", "2"),
new XAttribute("BorderBrush", "{DynamicResource {x:Static themes:RibbonCommonDictionary.WindowBackgroundBrushKey}}"),
new XAttribute("CornerRadius", "2"),
new XAttribute("Padding", "10"),
new XElement("StackPanel",
new XElement("TextBlock",
new XAttribute("Text", "{Binding Path=Notation}")),
new XElement("TextBlock",
new XAttribute("Text", "{Binding Path=Precision}")),
new XElement("TextBlock",
new XAttribute("Text", "{Binding Path=Overwrite}")))));
string xaml = element.ToString();
MemoryStream sr = new MemoryStream(Encoding.ASCII.GetBytes(xaml));
ParserContext pc = new ParserContext();
pc.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
pc.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
pc.XmlnsDictionary.Add("themes", "clr-namespace:ActiproSoftware.Windows.Controls.Ribbon.Themes;assembly=ActiproSoftware.Ribbon.WPF30");
DataTemplate datatemplate = (DataTemplate)XamlReader.Load(sr, pc);
return datatemplate;