皆さん、こんにちは。
WPF アプリケーション (VS 2010) に XamDataGrid があり、1 つのフィールドのコントロール テンプレートをプログラムで追加する必要があります (フィールドは常にアプリのコードから追加されます)。
したがって、XAML でテンプレートを作成する代わりに、次のようにコードから作成しています (同様の問題を説明するいくつかの投稿に従いました)。
Field f = new Field { Name = name, Label = label, Width = new FieldLength(20) };
Style cellStyle = new System.Windows.Style();
string templateStr = "<ControlTemplate TargetType=\"{x:Type igDP:CellValuePresenter}\">" +
"<Button Content=\"Flu\" />" +
"</ControlTemplate>";
ParserContext pc = new ParserContext();
pc.XmlnsDictionary.Add("", "http://schemas.microsoft.com/winfx/2006/xaml/presentation");
pc.XmlnsDictionary.Add("x", "http://schemas.microsoft.com/winfx/2006/xaml");
pc.XmlnsDictionary.Add("igDP", "http://infragistics.com/DataPresenter");
ControlTemplate ct = (ControlTemplate)XamlReader.Parse(templateStr, pc);
cellStyle.Setters.Add(new Setter() { Property = CellValuePresenter.TemplateProperty, Value = ((object)new CellValuePresenter() { Template = ct }) });
f.Settings.CellValuePresenterStyle = cellStyle;
MainDataGrid.FieldLayouts[0].Fields.Add(f);
どういうわけかこれが機能せず、フィールド/列が表示されません。したがって、これは機能していません。助けていただければ幸いです。