层次结构为网格
我有层次结构:
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
{
}
和带有模板的 XAML
<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>
这看起来像:
Param1 -Control----
Param2 -Control----
Complex1
Sub Param1 -Control-
Sub Param2 -Control-
或此处的图像: freeimagehosting.net/uploads/9d438f52e7.png
问题
如何仅在左列(参数名称)中缩进。 像这样的东西:
Param1 -Control----
Param2 -Control----
Complex1
Sub Param1 -Control----
Sub Param2 -Control----
或者图片在这里:freeimagehosting.net/uploads/4ab3045b75.png
抱歉,但我无法添加网址和图像:(
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 :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,此任务没有简单的决策,因为视图模型应该提供有关层次结构中节点级别的信息。如果提供级别来查看模型,我可以使用 此决定。
也很有趣此示例。
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.