WPF 工具包数据网格样式

发布于 2024-09-19 23:56:58 字数 3003 浏览 3 评论 0原文

我希望找到有关从 WPF 工具包 2010 自定义 Datagrid 的答案。我想在数据网格的 DataGridColumnHeaderPresenter 上方添加一个 TITLE 区域。问题是我希望它作为用户控件或数据模板,我可以在其中从 XML 填充标题。我希望在一页上为从一个 XML 获取数据的多个数据网格设置唯一的标题。我在同一窗口中填充几个数据网格。为从 XML 填充并绑定到每个数据网格的内容添加可自定义平铺区域以避免重复的最佳解决方案是什么?

先感谢您。我用这种方式生成带有列的数据网格:

<Custom:DataGrid Grid.Column="0" Grid.Row="1" x:Name="ServerList" ItemsSource="{Binding Source={StaticResource PagesData}, XPath=ListTiles/Tile1}">
<Custom:DataGrid.Columns>
    <Custom:DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}"  />
    <Custom:DataGridTextColumn Header="Status" Binding="{Binding XPath=@Status}"  />
    <Custom:DataGridTextColumn Header="Events" Binding="{Binding XPath=@Events}"  />
    <Custom:DataGridTextColumn Header="Services" Binding="{Binding XPath=@Services}" />
</Custom:DataGrid.Columns>

<Custom:DataGrid x:Name="Events" Grid.Column="0" Grid.Row="2" ItemsSource="{Binding Source={StaticResource PagesData}, XPath=ListTiles/Tile2}" >
<Custom:DataGrid.Columns>
    <Custom:DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}" />
    <Custom:DataGridTextColumn Header="Level" Binding="{Binding XPath=@Level}" />
    <Custom:DataGridTextColumn Header="Source" Binding="{Binding XPath=@Source}" />
    <Custom:DataGridTextColumn Header="In last 24h" Binding="{Binding XPath=@TimeSpan}" />
</Custom:DataGrid.Columns>

<Custom:DataGrid x:Name="Services" Grid.Column="2" Grid.Row="2" ItemsSource="{Binding Source={StaticResource PagesData}, XPath=ListTiles/Tile3}">
<Custom:DataGrid.Columns>
    <Custom:DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}" />
    <Custom:DataGridTextColumn Header="Status" Binding="{Binding XPath=@Status}" />
    <Custom:DataGridTextColumn Header="Start" Binding="{Binding XPath=@Start}" />
    </Custom:DataGrid.Columns>

XML:

<?xml version="1.0" encoding="utf-8"?>
<ListTiles  xmlns="">
<Tile1>
<Header Title="ROLES &amp; GROUPS" />
<Server Name="Kim" Status="ready" Events="1" Services="1" />
<Server Name="Sherri" Status="past" Events="2" Services="1"/>
<Server Name="Mike" Status="future" Events="3" Services="1" />
</Tile1> 
<Tile2>
<Header Title="EVENTS" />
<Server Name="Young"  Level="average" Source="home" TimeSpan="5" />
<Server Name="Sarah"  Level="Critical" Source="work" TimeSpan="6" />
<Server Name="Susan"  Level="normal" Source="friend" TimeSpan="2" />
</Tile2>
<Tile3>
 <Header Title="SERVICES" />
 <Server Name="Josh" DisplayName="FF" Status="Running" Start="Auto" />
 <Server Name="Amy" DisplayName="DD" Status="Rest" Start="Auto" />
 <Server Name="Bill" DisplayName="AS" Status="Work" Start="Auto" />
</Tile3>
</ListTiles>

I hope to find an answer on customizing Datagrid from WPF toolkit 2010. I'd like to add a TITLE area to be above DataGridColumnHeaderPresenter of the datagrid. The problem is that I want it to be as a user control or data template where I can populate the title from XML. I want to have unique titles for multiple datagrids on one page getting data from one XML. I populate few datagrids in the same window. What will be the best solution to add customizable Tile area for a content populated from XML and bounded to each datagrid to avoid dublication?

Thank you in advance. I generate datagrid with columns this way:

<Custom:DataGrid Grid.Column="0" Grid.Row="1" x:Name="ServerList" ItemsSource="{Binding Source={StaticResource PagesData}, XPath=ListTiles/Tile1}">
<Custom:DataGrid.Columns>
    <Custom:DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}"  />
    <Custom:DataGridTextColumn Header="Status" Binding="{Binding XPath=@Status}"  />
    <Custom:DataGridTextColumn Header="Events" Binding="{Binding XPath=@Events}"  />
    <Custom:DataGridTextColumn Header="Services" Binding="{Binding XPath=@Services}" />
</Custom:DataGrid.Columns>

<Custom:DataGrid x:Name="Events" Grid.Column="0" Grid.Row="2" ItemsSource="{Binding Source={StaticResource PagesData}, XPath=ListTiles/Tile2}" >
<Custom:DataGrid.Columns>
    <Custom:DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}" />
    <Custom:DataGridTextColumn Header="Level" Binding="{Binding XPath=@Level}" />
    <Custom:DataGridTextColumn Header="Source" Binding="{Binding XPath=@Source}" />
    <Custom:DataGridTextColumn Header="In last 24h" Binding="{Binding XPath=@TimeSpan}" />
</Custom:DataGrid.Columns>

<Custom:DataGrid x:Name="Services" Grid.Column="2" Grid.Row="2" ItemsSource="{Binding Source={StaticResource PagesData}, XPath=ListTiles/Tile3}">
<Custom:DataGrid.Columns>
    <Custom:DataGridTextColumn Header="Name" Binding="{Binding XPath=@Name}" />
    <Custom:DataGridTextColumn Header="Status" Binding="{Binding XPath=@Status}" />
    <Custom:DataGridTextColumn Header="Start" Binding="{Binding XPath=@Start}" />
    </Custom:DataGrid.Columns>

XML:

<?xml version="1.0" encoding="utf-8"?>
<ListTiles  xmlns="">
<Tile1>
<Header Title="ROLES & GROUPS" />
<Server Name="Kim" Status="ready" Events="1" Services="1" />
<Server Name="Sherri" Status="past" Events="2" Services="1"/>
<Server Name="Mike" Status="future" Events="3" Services="1" />
</Tile1> 
<Tile2>
<Header Title="EVENTS" />
<Server Name="Young"  Level="average" Source="home" TimeSpan="5" />
<Server Name="Sarah"  Level="Critical" Source="work" TimeSpan="6" />
<Server Name="Susan"  Level="normal" Source="friend" TimeSpan="2" />
</Tile2>
<Tile3>
 <Header Title="SERVICES" />
 <Server Name="Josh" DisplayName="FF" Status="Running" Start="Auto" />
 <Server Name="Amy" DisplayName="DD" Status="Rest" Start="Auto" />
 <Server Name="Bill" DisplayName="AS" Status="Work" Start="Auto" />
</Tile3>
</ListTiles>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文