Reputation: 378
The Error:
System.Windows.Markup.XamlParseException: ''Can't create unknown type '{schemas.xceed.com/wpf/xaml/toolkit}DoubleUpDown'.' (line number: '1'; line position: '1706').'
I got the following code:
ParserContext context = new ParserContext();
context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
context.XmlnsDictionary.Add("materialDesign", "http://materialdesigninxaml.net/winfx/xaml/themes");
context.XmlnsDictionary.Add("smtx", "clr-namespace:ShowMeTheXAML;assembly=ShowMeTheXAML");
context.XmlnsDictionary.Add("l", "clr-namespace:UIControls;assembly=UIControls");
context.XmlnsDictionary.Add("d", "http://schemas.microsoft.com/expression/blend/2008");
context.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
context.XmlnsDictionary.Add("mc", "http://schemas.openxmlformats.org/markup-compatibility/2006");
context.XmlnsDictionary.Add("sys", "clr-namespace:System;assembly=mscorlib");
context.XmlnsDictionary.Add("xctk", "http://schemas.xceed.com/wpf/xaml/toolkit");
Encoding encoding = Encoding.UTF8;
var ecod = new System.IO.MemoryStream(encoding.GetBytes(xaml));
TabItem element = (TabItem)XamlReader.Load(ecod, context);
DataControl.Items.Add(element);
As request of @mm8 this is a smaller string xaml:
string xaml = "<TabItem>" +
"<TabItem.Header>" +
"<StackPanel Orientation='Horizontal'>" +
"<TextBlock Text='Neutral' Foreground='Black' HorizontalAlignment='Center' VerticalAlignment='Center' Margin='0,0,0,0'/>" +
"</StackPanel>" +
"</TabItem.Header>" +
"<Grid Margin='0,20,0,0'>" +
"<Grid.ColumnDefinitions>" +
"<ColumnDefinition Width='1*'/>" +
"<ColumnDefinition Width='2*'/>" +
"<ColumnDefinition Width='1*'/>" +
"<ColumnDefinition Width='2*'/>" +
"</Grid.ColumnDefinitions>" +
"<StackPanel Grid.Column='0' Orientation='Vertical' HorizontalAlignment='Right'>" +
"<Label HorizontalAlignment='Right'>Sueldo:</Label>" +
"<Label HorizontalAlignment='Right'>Horas semanales:</Label>" +
"<Label HorizontalAlignment='Right'>Valor hora extra:</Label>" +
"<Label HorizontalAlignment='Right'>Valor hora extra nocturna:</Label>" +
"</StackPanel>" +
"<StackPanel Grid.Column='1' Orientation='Vertical'>" +
"<xctk:DoubleUpDown FontSize='16'/>" +
"<xctk:DoubleUpDown FontSize='16'/>" +
"<xctk:DoubleUpDown FontSize='16'/>" +
"<xctk:DoubleUpDown FontSize='16'/>" +
"</StackPanel>" +
"<StackPanel Grid.Column='2' Orientation='Vertical' HorizontalAlignment='Right'>" +
"<Label HorizontalAlignment='Right'>Valor de la hora(no extra):</Label>" +
"</StackPanel>" +
"<StackPanel Margin='10,0,0,0' Grid.Column='3' Orientation='Vertical' HorizontalAlignment='Left'>" +
"<TextBlock FontSize='18' Height='23'/>" +
"</StackPanel>" +
"</Grid>" +
"</TabItem>";
Those controls are giving me the error, I get it as if the resource is not being called though I call it in the ParserContext as you can see in the code.
If I add it manually in the XAML it works like a charm, other dll resources are working so I don't think is all about BuildAction.
What am I missing? Any other way to do this?
Upvotes: 0
Views: 2304
Reputation: 378
Mapping the assembly in the parser like this:
context.XmlnsDictionary.Add("xctk", "clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit");
Instead of like this:
context.XmlnsDictionary.Add("xctk", "http://schemas.xceed.com/wpf/xaml/toolkit");
Fixed the problem.
Upvotes: 4