C# 如何转换一个";xaml字符串“;模板到可编译的xaml/控件
这是存储在资源文件中的现有“Xaml字符串”模板C# 如何转换一个";xaml字符串“;模板到可编译的xaml/控件,c#,silverlight,xaml,C#,Silverlight,Xaml,这是存储在资源文件中的现有“Xaml字符串”模板 <telerik:GridViewDataColumn DataMemberBinding="{Binding <<PropertyName>>}" IsReadOnlyBinding="{Binding Is<<PropertyName>>ReadOnly}"> <telerik:GridViewDataColumn.CellEditTempla
<telerik:GridViewDataColumn
DataMemberBinding="{Binding <<PropertyName>>}"
IsReadOnlyBinding="{Binding Is<<PropertyName>>ReadOnly}">
<telerik:GridViewDataColumn.CellEditTemplate>
<DataTemplate>
<StackPanel >
<!--some more markup with similar bindings here-->
</StackPanel >
</DataTemplate>
</telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
在代码隐藏中,我使用XamlReader为列创建标记,然后将其添加到网格中
var xamlTemplate = Properties.Resources.GridColumnTemplate.Replace( "<<PropertyName>>", "MyProperty");
var col = ( GridViewDataColumn )XamlReader.Load( xamlTemplate );
detailsGrid.Columns.Add( col );
var xamlTemplate=Properties.Resources.GridColumnTemplate.Replace(“,“MyProperty”);
var col=(GridViewDataColumn)XamlReader.Load(xamlTemplate);
detailsGrid.Columns.Add(col);
现在,我需要用一个可编译的Xaml/控件来代替它。
有办法吗
我曾想过广泛使用转换器并绑定到MyProperty的上下文,但这听起来不是一个好的解决方案。一个选项是:
- 使用自己的依赖属性派生自己的列控件(来自telerik控件)
- 循环浏览您的属性集合:
- 创建列控件的实例
- 设置绑定