我加载了一系列动态创建的 GridView。一切正常,除非展开行详细信息时出现错误“无法创建未知类型'{clr-namespace:EMR.Controls.HPI}HPIDialogButton'。命名空间 EMR.Controls.HPI 在执行程序集中,我可以使用其他地方完全相同的 XAML,它可以正常工作。如果我注释掉“hpi:HPIDialogButton...”行,那么行详细信息会毫无问题地展开。
如果您直接执行操作,似乎在加载点会丢失一些为您创建的连接。
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);
}