(Level-1)
Scalar ---value
Enum ---value
String ---Value
Boolean ---value
Array
(Level-2)
-Array
(Level-3)
-Scalar ---value
-Enum ---value
-String ---Value
-Boolean ---value
-Scalar ---value
-Enum ---value
-String ---Value
-Boolean ---value
我必须显示树视图,如上面的树所示。 1级项目是枚举,标量,布尔值,字符串,数组对象。我编写了templateSelector来为每个1级对象选择不同的模板。我能够为1级类型编写数据模板。但是如何为"数组类型"编写模板?因为它再次包含1级项目作为其项目(级别2)。 3级的同样问题。只允许3级。
<local:ParameterTemplateSelector x:Key="ParameterTemplateSelector"></local:ParameterTemplateSelector>
<DataTemplate x:Key="ScalarTemplate">
<StackPanel Orientation="Horizontal">
<Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>
<TextBox Text="{Binding Value.Item.Value}" Width="100" TextAlignment="Center"></TextBox>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="EnumTemplate">
<StackPanel Orientation="Horizontal">
<Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>
<TextBox Text="{Binding Value.Item.Value}" Width="100" TextAlignment="Center"></TextBox>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="StringTemplate">
<StackPanel Orientation="Horizontal">
<Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>
<TextBox Text="{Binding Value.Item}" Width="100" TextAlignment="Center"></TextBox>
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="BooleanTemplate">
<StackPanel Orientation="Horizontal">
<Label FontWeight="Bold" Width="80" Content="{Binding parameterCode}"></Label>
<ComboBox Width="100" SelectedIndex="{Binding Value.Item, Converter={StaticResource boolToIndexConverter}}">
<ComboBoxItem Tag="1">True</ComboBoxItem>
<ComboBoxItem Tag="0">False</ComboBoxItem>
</ComboBox>
<!--<TextBox Text="{Binding Value.Item}" Width="100" TextAlignment="Center"></TextBox>-->
</StackPanel>
</DataTemplate>