Hi,
I want to set the Itemtemplate of a xamtreeitem in the viewmodel, unfortunatly this throws following exception:
"System.Windows.Markup.XamlParseException occurred Message=Nicht deklariertes Präfix. [Line: 3 Position: 156]"
Normal 0 21 false false false DE X-NONE X-NONE MicrosoftInternetExplorer4
Below is an excerpt from the code. The logic for the method I've attached.
if (Application.Current.Resources["AttributingReadyToImageSourceConverter"] == null) { throw new Exception("XamlParseException - AttributingReadyToImageSourceConverter"); }
string dataTemplate = @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"">
<StackPanel Orientation=""Horizontal"">
<ig:XamTreeItem IsEnabled=""{Binding ArticleCodeModel.CodeModel.AttributingReady}"" Loaded=""XamTreeItem_Loaded"" />
<Image Width=""15"" Height=""15"" Margin=""5,0,0,0"" HorizontalAlignment=""Right"" Loaded=""Image_Loaded"" Source=""{Binding ArticleCodeModel.CodeModel.AttributingReady, Converter={StaticResource AttributingReadyToImageSourceConverter}}"" />
</StackPanel>
</DataTemplate>";
newItem.ItemTemplate = (DataTemplate)XamlReader.Load(dataTemplate);
Thank you very much!
Best regards, Djumana
You should define the ig namespace in your datatemplate as well, because you use ig element inside the datatemplate.
This is one of the reasons you get XamlParseException. If you still get an exception after you add the ig xmlns, please attach a sample that reproduces the issue so I can debug it and try to help you.
Update: Note that xamlReader won't be able to access your converter from the app resources.You will need to define the converter inside the datatemplete. Check this article and use the approach from the second part of the article.
Regards
thank you very much for your quick reply.
Now I have following exception, when I click the tree item on first level:
e.ExceptionObject = {System.Exception: Beim Aufruf einer COM-Komponente wurde ein HRESULT E_FAIL-Fehler zurückgegeben.}
if (Application.Current.Resources["ActiveClassificationTreeAttributingReadyToImageSourceConverter"] == null) { throw new Exception("XamlParseException - ActiveClassificationTreeAttributingReadyToImageSourceConverter"); } string dataTemplate = @"<DataTemplate xmlns=""http://schemas.microsoft.com/client/2007"" xmlns:ig=""clr-namespace:Infragistics.Controls.Menus;assembly=InfragisticsSL4.Controls.Menus.XamTree.v11.1""> <StackPanel Orientation=""Horizontal""> <ig:XamTreeItem IsEnabled=""{Binding ArticleCodeModel.CodeModel.AttributingReady}"" Loaded=""XamTreeItem_Loaded"" /> <Image Width=""15"" Height=""15"" Margin=""5,0,0,0"" HorizontalAlignment=""Right"" Loaded=""Image_Loaded"" Source=""{Binding ArticleCodeModel.CodeModel.AttributingReady, Converter={StaticResource ActiveClassificationTreeAttributingReadyToImageSourceConverter}}"" /> </StackPanel> </DataTemplate>"; newItem.ItemTemplate = (DataTemplate)XamlReader.Load(dataTemplate);
Unfortunately without a sample application my hands are tight. Could you send a sample that reproduces the issue?
Thanks
I am Newbie. I can't make a little example.
Maybe you want show me one little example, then I will try it like you done.
Thank you and sorry
I found out the problem. The exception occurs because of the "Loaded"-methods.
String dataTemplate = @"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:DataMapping.Converter=""clr-namespace:IFCC.DataManager.Helpers.Converter"" xmlns:ig=""clr-namespace:Infragistics.Controls.Menus;assembly=InfragisticsSL4.Controls.Menus.XamTree.v11.1""> <StackPanel Orientation=""Horizontal""> <ig:XamTreeItem IsEnabled=""{Binding ArticleCodeModel.CodeModel.AttributingReady}"" Loaded=""XamTreeItem_Loaded""/> <Image Width=""15"" Height=""15"" Margin=""5,0,0,0"" HorizontalAlignment=""Right"" Loaded=""Image_Loaded"" Source=""{Binding ArticleCodeModel.CodeModel.AttributingReady, Converter={StaticResource ActiveClassificationTreeAttributingReadyToImageSourceConverter}}"" /> </StackPanel> </DataTemplate>";
How can I implement it properly? Many thanks for your efforts!