Domanda

I've been trying to figure out how to recreate this "complex" datagrid header, binded to an XML file. I haven't found any examples about how to tackle this problem.

This is an example XML data file (which can have more 'sensors' and more 'Measures'):

<?xml version="1.0" encoding="utf-8" ?>
<ShipData>
  <Draught>
    <Measures>
      <Mdata>M1</Mdata>
      <Mdata>M2</Mdata>
    </Measures>
    <Sensor Name="Sensor1">
      <Measurement>
        <Bis>45</Bis>
        <Man>43</Man>
      </Measurement>
      <Measurement>
        <Bis>44</Bis>
        <Man>46</Man>
      </Measurement>
    </Sensor>
    <Sensor Name="Sensor2">
      <Measurement>
        <Bis>45</Bis>
        <Man>43</Man>
      </Measurement>
      <Measurement>
        <Bis>43</Bis>
        <Man>45</Man>
      </Measurement>
    </Sensor>
  </Draught>
</ShipData>

And this is how I would style my datagrid:

datagrid with customized double-lined header

Since the data can change (more sensors, and more measures), I'll be doing some code behind loading of the datagrid.

Edit: So the things I'm trying to do is:

  1. Create the header (consisting of two lines, the upper line spanning two columns)

    (solved) >> Since you can't really span multiple columns for the header, the best way is to create a grid, just above the Datagrid with equal possible solution

    You could play with:

    <DataGrid.Columns>
      <DataGridTemplateColumn>
        <DataGridTemplateColumn.HeaderTemplate>                                    
          <DataTemplate> ...
    

    ... but it get's ugly...at least here. I don't think the HeaderTemplate is used for the things I want to do.

  2. Bind the xml data to the grid

    Still figuring out (and how to save changes to the data back to the file)

Preferably via code behind

È stato utile?

Soluzione

I solved the problem about the "super" header (see above for example):

Since you can't really span multiple columns for the header, the best way is to create a grid, just above the Datagrid with equal column sizes (or combined sizes for the super header)

I'm stil struggling with the code behind xmlprovider and xpath (but I'll make a new question to not pollute this question any further)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top