Hierarchy as grid

Posted by seesharp on Stack Overflow See other posts from Stack Overflow or by seesharp
Published on 2010-06-10T02:40:07Z Indexed on 2010/06/10 2:42 UTC
Read the original article Hit count: 290

Filed under:
|
|
|
|

I have hierarchy:

public class Parameter
{
    public string Name { get; set; }
    public Value Value { get; set; }
}

public abstract class Value
{
}

public class StringValue : Value
{
    public string Str { get; set; }
}

public class ComplexValue : Value
{
    public ComplexValue()
    {
        Parameters = new List<Parameter>();
    }

    public List<Parameter> Parameters { get; set; }
}

/// Contains ComplexValue
public class ComplexParameter : Parameter
{
}

And XAML with templates

<Window.Resources>
    <DataTemplate DataType="{x:Type pc:Parameter}">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <Label Grid.Column="0" Content="{Binding Name}"/>
            <ContentPresenter Grid.Column="1" Content="{Binding Value}"/>
        </Grid>
    </DataTemplate>

    <DataTemplate DataType="{x:Type pc:ComplexParameter}">
        <StackPanel>
            <Label Content="{Binding Name}"/>
            <ContentControl Margin="18,0,0,0" Content="{Binding Value}"/>
        </StackPanel>
    </DataTemplate>

    <DataTemplate DataType="{x:Type pc:ComplexValue}">
        <ItemsControl ItemsSource="{Binding Parameters}"/>
    </DataTemplate>

    <DataTemplate DataType="{x:Type pc:StringValue}">
        <TextBox Text="{Binding Str}"/>
    </DataTemplate>

</Window.Resources>

This look like:

Param1         -Control----
Param2         -Control----
  Complex1
    Sub Param1    -Control-
    Sub Param2    -Control-

Or image here: freeimagehosting.net/uploads/9d438f52e7.png

Question

How to do indent only in left column (parameter names). Something like this:

Param1         -Control----
Param2         -Control----
  Complex1
    Sub Param1 -Control----
    Sub Param2 -Control----

Or image here: freeimagehosting.net/uploads/4ab3045b75.png

© Stack Overflow or respective owner

Related posts about c#

Related posts about wpf