문제

I have a series of dynamically created GridViews that I load. Everything works fine except when the row details are expanded I get an error "Cannot create unknown type '{clr-namespace:EMR.Controls.HPI}HPIDialogButton'. The namespace EMR.Controls.HPI is in the executing assembly and I can use the exact same XAML other places and it works without problems. If I comment out the line 'hpi:HPIDialogButton...' then the row details expand without problems.

It seems at the loading point there is some connection missing that is created for you if you do things directly.

   private RadGridView BuildSectionGrid()
    {
      //This is defined here until a better solution is found
      string XAML = @"
          <my:RadGridView IsReadOnly=""False"">
            <my:RadGridView.Columns>
                <telerik:GridViewToggleRowDetailsColumn />
                <telerik:GridViewDataColumn Header=""Selected"" DataMemberBinding=""{Binding IsSelected}"" IsReadOnly=""False""/>
                <telerik:GridViewDataColumn Header=""Definition"" DataMemberBinding=""{Binding Definition}"" IsReadOnly=""True""/>
            </my:RadGridView.Columns>

            <my:RadGridView.RowDetailsTemplate>
                <DataTemplate>
                    <DockPanel Margin=""10"">
                        <Label Content=""Progress Note:"" DockPanel.Dock=""Left""/>
                        <hpi:HPIDialogButton Margin=""5 0 0 0"" DockPanel.Dock=""Right"" HPIText=""{Binding ElementName=NoteItemTextBox, Path=Text, Mode=TwoWay}""/>
                        <TextBox Name=""NoteItemTextBox"" Margin=""5 0 0 0"" DockPanel.Dock=""Left"" AcceptsReturn=""True"" TextWrapping=""Wrap"" Height=""100"" Text=""{Binding ProgressNote}""/>
                    </DockPanel>
                </DataTemplate>
            </my:RadGridView.RowDetailsTemplate>
        </my:RadGridView>
";


      //Load the XAML in again
      ParserContext Context = new ParserContext();
      Context.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
      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("telerik", "http://schemas.telerik.com/2008/xaml/presentation");
      Context.XmlnsDictionary.Add("hpi", "clr-namespace:EMR.Controls.HPI");
      Context.XmlnsDictionary.Add("my", "clr-namespace:EMR.Shared.Controls.WPF;assembly=EMR.Shared.Controls.WPF");
      return (RadGridView)XamlReader.Parse(XAML, Context);
    }
도움이 되었습니까?

해결책

Try to specify assembly in all your xmlns (you miss it in one):

Context.XmlnsDictionary.Add("hpi", "clr-namespace:EMR.Controls.HPI;assembly=EMR.Controls.HPI");

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top