TreeView Binding Problem
-
I have a set of hierarchal data contained in classes that is loaded from a serialized XML file. Once deserialized, the objects have this format:
Root
|_ Groups
|_Rules
|_Conditions
|_ Actions
|_ ObjectsI have set up the necessesary HierarchicalDataTemplates for the Groups, Rules, and Conditions, and they show fine in the TreeView. I also set up a DataTemplate for the Actions and one for the Objects, but only Actions is showing. The reason is that because in the HierarchicalDataTemplate for the Condition the ItemSource is pointing to Actions:
<!-- Condition -->
<HierarchicalDataTemplate DataType="{x:Type local:RuleCondition}" ItemsSource="{Binding Path=Actions, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<Image Source="/RulesEngineUI;component/Media/bluedot.png" Height="8" Width="8" Margin="0,0,3,0"/>
<TextBlock Margin="0,0,5,0" FontWeight="Bold">Condition:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=Operation}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate><!-- Action -->
<DataTemplate DataType="{x:Type local:RuleAction}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0" FontWeight="Bold">Action:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=ActionField}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate><!-- Object -->
<DataTemplate DataType="{x:Type local:RuleObject}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0" FontWeight="Bold">Object:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=Field}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>If you look at the Condtion HierarchicalDataTemplate you see that it refers to actions. How do I tell
-
I have a set of hierarchal data contained in classes that is loaded from a serialized XML file. Once deserialized, the objects have this format:
Root
|_ Groups
|_Rules
|_Conditions
|_ Actions
|_ ObjectsI have set up the necessesary HierarchicalDataTemplates for the Groups, Rules, and Conditions, and they show fine in the TreeView. I also set up a DataTemplate for the Actions and one for the Objects, but only Actions is showing. The reason is that because in the HierarchicalDataTemplate for the Condition the ItemSource is pointing to Actions:
<!-- Condition -->
<HierarchicalDataTemplate DataType="{x:Type local:RuleCondition}" ItemsSource="{Binding Path=Actions, Mode=TwoWay}">
<StackPanel Orientation="Horizontal">
<Image Source="/RulesEngineUI;component/Media/bluedot.png" Height="8" Width="8" Margin="0,0,3,0"/>
<TextBlock Margin="0,0,5,0" FontWeight="Bold">Condition:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=Operation}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate><!-- Action -->
<DataTemplate DataType="{x:Type local:RuleAction}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0" FontWeight="Bold">Action:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=ActionField}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate><!-- Object -->
<DataTemplate DataType="{x:Type local:RuleObject}">
<StackPanel Orientation="Horizontal">
<TextBlock Margin="0,0,5,0" FontWeight="Bold">Object:</TextBlock>
<TextBlock>
<Hyperlink Name="Link" Style="{StaticResource LinkStyle}" Click="Link_Click">
<TextBlock Text="{Binding Path=Field}"></TextBlock>
</Hyperlink>
</TextBlock>
</StackPanel>
</DataTemplate>If you look at the Condtion HierarchicalDataTemplate you see that it refers to actions. How do I tell
Hi, from your structure I assume your intention is to have several Action/Object-pairs under each condition and to accomplish that, you created two lists of identical length: one of Objects and one of Actions. You should replace the two lists with one list of a combined class like:
public class CombinedClass
{
public RuleObject { get; set; }
public RuleAction { get; set; }
}Then it should be almost self-solving!? But maybe, I got your structure wrong. Cheers Jürgen