views:

47

answers:

1

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

Sorry, but I cannot add urls and images :(

A: 

As I understand, this task does not have simple decision, because view model should provide information about level of node in hierarchy. If provide level to view model, I can use this decision.

Also intresting this example.

SeeSharp