Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
851
Setting ItemTemplate in ViewModel throws an exception
posted

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

 

Parents
No Data
Reply
  • 6912
    Suggested Answer
    posted

    Hi,

    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

Children