将 DataGrid-GroupStyle XAML 重写为 C# 代码
有人可以将此 XAML 重写为 C# 代码吗?
<DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</DataGrid.GroupStyle>
我尝试了这个,但它不起作用:
// Setup Grouping
GroupStyle groupStyle = new GroupStyle();
groupStyle.ContainerStyle.Resources.FindName("GroupHeaderStyle");
groupStyle.Panel = new DataGridRowsPresenter();
无法让最后一行工作...
更新:
// Setup Grouping
GroupStyle groupStyle = new GroupStyle();
groupStyle.ContainerStyle.Resources.FindName("GroupHeaderStyle");
groupStyle.Panel = new ItemsPanelTemplate(new FrameworkElementFactory(typeof(DataGridRowsPresenter)));
Can someone please rewrite this XAML into C# code ?
<DataGrid.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
<GroupStyle.Panel>
<ItemsPanelTemplate>
<DataGridRowsPresenter/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</DataGrid.GroupStyle>
I tried this but it did not work:
// Setup Grouping
GroupStyle groupStyle = new GroupStyle();
groupStyle.ContainerStyle.Resources.FindName("GroupHeaderStyle");
groupStyle.Panel = new DataGridRowsPresenter();
Can`t get the last Line working...
UPDATE:
// Setup Grouping
GroupStyle groupStyle = new GroupStyle();
groupStyle.ContainerStyle.Resources.FindName("GroupHeaderStyle");
groupStyle.Panel = new ItemsPanelTemplate(new FrameworkElementFactory(typeof(DataGridRowsPresenter)));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该可以做到:)
This should do it :)
此链接一定有帮助: http://www.netframeworkdev.com/windows-presentation-foundation-wpf/setting-an-itemscontrolpanels-content-from-code-86898.shtml
顺便说一句,您可能想要
而不是
编辑:
为了获得正确的容器,您需要从资源中获取它。这些要么是窗口资源,要么是应用程序范围的资源。我想
Application.Current.Resources.FindName("GroupHeaderStyle");
应该找到正确的资源,除非您正在做一些特殊的事情。This link must be helpful: http://www.netframeworkdev.com/windows-presentation-foundation-wpf/setting-an-itemscontrolpanels-content-from-code-86898.shtml
BTW, you perhaps want
instead of
Edit:
in order to get the container correct, you need to get it from the resources. These are either Window resources, or the application-wide resources. I guess
Application.Current.Resources.FindName("GroupHeaderStyle");
should find the correct resources, unless you are doing something special.