将XAML转换为C#

将XAML转换为C#,c#,xaml,C#,Xaml,我没有在网上找到它 帮助将此代码重写为C# 进行数据网格分组尝试将第一行替换为: Style GroupStyle = new Style() { TargetType = typeof(GroupItem) }; x:Type标记扩展与C中的typeof()运算符具有类似的功能# 尝试将第一行替换为: Style GroupStyle = new Style() { TargetType = typeof(GroupItem) }; x:Type标记扩展与C中的typeof()运算符具有类

我没有在网上找到它
帮助将此代码重写为C#


进行数据网格分组

尝试将第一行替换为:

Style GroupStyle = new Style() { TargetType = typeof(GroupItem) };
x:Type
标记扩展与C中的
typeof()
运算符具有类似的功能#

尝试将第一行替换为:

Style GroupStyle = new Style() { TargetType = typeof(GroupItem) };
x:Type
标记扩展与C中的
typeof()
运算符具有类似的功能#

正如@arconaut所说,第一行应该使用
typeof
。因此,第一条树线是:

Style-GroupStyle=newstyle(){TargetType=typeof(GroupItem)};
Setter Setter=new Setter{Property=Control.TemplateProperty};
ControlTemplate=new ControlTemplate{TargetType=typeof(GroupItem)};
然后我相信基于上述XAML,
IsExpandedProperty
应该设置为
True

expander.SetValue(expander.IsExpandedProperty,true);
最后,您需要在最后两行中将
FrameworkElementFactory
作为
SetValue()
的参数传递

expander.SetValue(expander.HeaderProperty,
新FrameworkElementFactory(typeof(TextBlock));
expander.SetValue(expander.ContentProperty,
新FrameworkElementFactory(typeof(ItemsPresenter));

正如@arconaut所说,第一行应该使用
typeof
。因此,第一条树线是:

Style-GroupStyle=newstyle(){TargetType=typeof(GroupItem)};
Setter Setter=new Setter{Property=Control.TemplateProperty};
ControlTemplate=new ControlTemplate{TargetType=typeof(GroupItem)};
然后我相信基于上述XAML,
IsExpandedProperty
应该设置为
True

expander.SetValue(expander.IsExpandedProperty,true);
最后,您需要在最后两行中将
FrameworkElementFactory
作为
SetValue()
的参数传递

expander.SetValue(expander.HeaderProperty,
新FrameworkElementFactory(typeof(TextBlock));
expander.SetValue(expander.ContentProperty,
新FrameworkElementFactory(typeof(ItemsPresenter));

代码中出现错误。?如果出现错误,请显示错误。在程序执行期间,请尝试
Style GroupStyle=new Style(){TargetType=Type.GetType(“System.Windows.Controls.GroupItem”)}
@jps,第一行的错误是System。ArgumentNullException@ChetanRanpariya同样的错误。代码中出现了一个错误?如果出现错误,请显示错误。在程序执行期间,请尝试
Style GroupStyle=new Style(){TargetType=Type.GetType(“System.Windows.Controls.GroupItem”)}
@jps,第一行的错误是System。ArgumentNullException@ChetanRanpariya同样的错误,谢谢,我换了1行和3行,但现在问题出在第6行。错误:System.NotSupportedException:“FrameworkElementFactory.SetValue”的“无效值”System.Windows.Controls.TextBlock。“不支持Visual或ContentElement派生的值。”我相信“Header”属性只接受字符串:
expander.SetValue(expander.HeaderProperty,这是标题”)
是,它可以工作,但是我不知道如何用分组数据填充它谢谢,我在第1行和第3行中替换了它,但是现在问题出现在第6行。错误:System.NotSupportedException:“FrameworkElementFactory.SetValue”的“无效值”System.Windows.Controls.TextBlock。“不支持Visual或ContentElement派生的值。”我相信“Header”属性只接受字符串:
expander.SetValue(expander.HeaderProperty,这是标题”)
是,它可以工作,但我不知道如何用数据来填充它们