-
November 14th, 2016, 06:08 AM
#1
I'm making multicolumn grid with subcolumns (source inside). But something goes wrong
I have xml:
Code:
<source>
<row>
<family>Expe</family>
<name>rium</name>
<kat>
<id>1</id>
<company>Mampf</company>
<date>17.1.2010</date>
</kat>
<kat>...</kat>
</row>
<row>
...
<kat>
<id>...</id>
<company>...</company>
<date>...</date>
</kat>
<kat>...</kat>
<kat>...</kat>
</row>
</source>
So I want to make table with 'family', 'name', and 'kat' colums. Column Kat has 'id', 'company' and 'date' subcolumns.
Working code is below.
What's wrong: in the first line I have full table in the third column. In the second line I have the same data in the third column.
How to address to the concrete <row> when reading <kat>? How to correct my xaml code?
And formatting, but it is easy quastion. I think I will resolve it myself.
Last edited by weyland; November 14th, 2016 at 07:02 AM.
Reason: mistype
-
November 14th, 2016, 06:09 AM
#2
Re: I'm doing multicolumn grid with subcolumns (source inside). But something goes wr
Full code:
Code:
<Window x:Class="MDTable.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="871.269">
<Window.Resources>
<XmlDataProvider x:Key="MDSource" d:IsDataSource="True" Source="Data/1.xml" />
<DataTemplate x:Key="familyTemplate">
<TextBlock Text="{Binding Mode=OneWay, XPath=family}" />
</DataTemplate>
<DataTemplate x:Key="nameTemplate">
<TextBlock Text="{Binding Mode=OneWay, XPath=name}" />
</DataTemplate>
<GridViewColumnCollection x:Key="Katcollection">
<GridViewColumn Header="id" DisplayMemberBinding="{Binding Mode=OneWay, XPath=id}"/>
<GridViewColumn Header="comp name" DisplayMemberBinding="{Binding Mode=OneWay, XPath=company}"/>
<GridViewColumn Header="date" DisplayMemberBinding="{Binding Mode=OneWay, XPath=date}"/>
</GridViewColumnCollection>
<Style x:Key="StretchHeaderStyle" TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="HorizontalContentAlignment" Value="Stretch"/>
</Style>
<DataTemplate x:Key="KataHeaderTemplate">
<Grid HorizontalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding}"
HorizontalAlignment="Center"/>
<GridViewHeaderRowPresenter Grid.Row="1"
HorizontalAlignment="Stretch"
Columns="{DynamicResource Katcollection}"/>
</Grid>
</DataTemplate>
<DataTemplate x:Key="KataCellTemplate2">
<GridViewRowPresenter HorizontalAlignment="Stretch"
Columns="{StaticResource Katcollection}"/>
</DataTemplate>
<DataTemplate x:Key="KataCellTemplate">
<Grid Margin="0">
<ListView Margin="0" ItemsSource="{Binding Mode=Default, Source={StaticResource MDSource}, XPath=rss/row/kat}"
IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView>
<GridViewColumn CellTemplate="{StaticResource KataCellTemplate2}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</DataTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot">
<ListView Margin="0" ItemsSource="{Binding Mode=Default, Source={StaticResource MDSource}, XPath=rss/row}"
IsSynchronizedWithCurrentItem="True">
<ListView.View>
<GridView ColumnHeaderContainerStyle="{StaticResource StretchHeaderStyle}">
<GridViewColumn Header="family"
CellTemplate="{StaticResource familyTemplate}" />
<GridViewColumn Header="name"
CellTemplate="{StaticResource nameTemplate}" />
<GridViewColumn Header="add info"
HeaderTemplate="{StaticResource KataHeaderTemplate}"
CellTemplate="{StaticResource KataCellTemplate}" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
Source 1.xml
Code:
<?xml version="1.0"?>
<rss>
<row>
<family>Ronya</family>
<name>Hoppa</name>
<kat>
<id>1</id>
<company>Mampf</company>
<date>17.1.2010</date>
</kat>
<kat>
<id>2</id>
<company>Rooby</company>
<date>17.2.2010</date>
</kat>
</row>
<row>
<family>Helio</family>
<name>roleo</name>
<kat>
<id>1</id>
<company>Jack</company>
<date>17.1.2010</date>
</kat>
<kat>
<id>2</id>
<company>Yorik</company>
<date>17.2.2010</date>
</kat>
<kat>
<id>4</id>
<company>Sony</company>
<date>11.2.2010</date>
</kat>
</row>
<row>
<family>12</family>
<name>1312</name>
<kat>
<id>1</id>
<company>q22wer</company>
<date>17.1.222010</date>
</kat>
<kat>
<id>44</id>
<company>4222</company>
<date>17.2.241242010</date>
</kat>
</row>
</rss>
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|