乔皮
您可以让 XamlReader 完成工作:
oDataTemplate = TryCast(System.Windows.Markup.XamlReader.Load(New System.Xml.XmlTextReader(New System.IO.StringReader(sXaml))), DataTemplate)
sXaml 我应该是这样的(在我的情况下,这是一个包含一些复选框的用户控件,这些复选框绑定到数据表字段):
Dim sDelim As String = vbNewLine
Try
sXaml = "<DataTemplate " & sDelim
sXaml = sXaml & " xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""" & sDelim
sXaml = sXaml & " xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""" & sDelim
sXaml = sXaml & " xmlns:local=""clr-namespace:Infor.Blending.Admin.Client;assembly=Infor.Blending.Admin.Client""" & sDelim
sXaml = sXaml & " xmlns:dg=""http://schemas.microsoft.com/wpf/2008/toolkit""" & sDelim
sXaml = sXaml & " >" & sDelim
sXaml = sXaml & " <local:RightEditor Tag=""Collapsed""" & sDelim
sXaml = sXaml & " Amend=""{Binding Path=Item.Right0, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGridRow}}}""" & sDelim
sXaml = sXaml & " Create=""{Binding Path=Item.Right1, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGridRow}}}""" & sDelim
sXaml = sXaml & " Delete=""{Binding Path=Item.Right2, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGridRow}}}""" & sDelim
sXaml = sXaml & " Review=""{Binding Path=Item.Right3, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type dg:DataGridRow}}}""" & sDelim
sXaml = sXaml & " />" & sDelim
sXaml = sXaml & " </DataTemplate>"
最后,您可以设置数据模板:
Dim oTemp As DataGridTemplateColumn = Nothing
oTemp.CellTemplate = oDataTemplate