チョッピー
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