I have beat my brains over this for a week. I've searched here and every other place for the answer. I'm stumped.
My program is basically a special purpose XML editor. I want to present the XML file in a TreeView control and have interior nodes represented as TextBlocks and leaf nodes as a TextBlock with the node name and a TextBox with the InnerText.
Here is an example of the XML:
<case>
<caseId>0</name>
<other case parameters>
...
</other case parameters>
</case>
I have gotten the data to display properly with the correct text in the TextBox, however when the data in the TextBox is modified the change is not propagated to the XML Document.
Here is the XAML that declares the TreeView
<TreeView Name="asifTreeView"
ItemTemplateSelector="{StaticResource treeItemTemplateSelector}"
SelectedItemChanged="asifTreeView_SelectedItemChanged"
ItemsSource="{Binding Mode=TwoWay, XPath=*}"
Margin="5"/>
The XmlDataProvider is the DataContext of the TreeViewItem. I have verified that the ItemTemplateSelector is returning the following DataTemplate:
<HierarchicalDataTemplate x:Key="textNodeTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ElementTB"/>
<TextBox x:Name="ElementBox"/>
</StackPanel>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="ElementTB"
Property="Text"
Value="{Binding Path=Name}"/>
<Setter TargetName="ElementBox"
Property="Text"
Value="{Binding Path=FirstChild.Data, Mode=TwoWay}"/>
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
When I modify the data in the text box nothing seems to happen. When I hit 'Enter' the PreviewTextInput event fires on the TreeView. The change does not propagate to the XML Document.
Is the binding I'm doing valid? Why is the data bound only one way?
Thanks for your help!
Bill
My program is basically a special purpose XML editor. I want to present the XML file in a TreeView control and have interior nodes represented as TextBlocks and leaf nodes as a TextBlock with the node name and a TextBox with the InnerText.
Here is an example of the XML:
<case>
<caseId>0</name>
<other case parameters>
...
</other case parameters>
</case>
I have gotten the data to display properly with the correct text in the TextBox, however when the data in the TextBox is modified the change is not propagated to the XML Document.
Here is the XAML that declares the TreeView
<TreeView Name="asifTreeView"
ItemTemplateSelector="{StaticResource treeItemTemplateSelector}"
SelectedItemChanged="asifTreeView_SelectedItemChanged"
ItemsSource="{Binding Mode=TwoWay, XPath=*}"
Margin="5"/>
The XmlDataProvider is the DataContext of the TreeViewItem. I have verified that the ItemTemplateSelector is returning the following DataTemplate:
<HierarchicalDataTemplate x:Key="textNodeTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="ElementTB"/>
<TextBox x:Name="ElementBox"/>
</StackPanel>
<HierarchicalDataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
<Setter TargetName="ElementTB"
Property="Text"
Value="{Binding Path=Name}"/>
<Setter TargetName="ElementBox"
Property="Text"
Value="{Binding Path=FirstChild.Data, Mode=TwoWay}"/>
</DataTrigger>
</HierarchicalDataTemplate.Triggers>
</HierarchicalDataTemplate>
When I modify the data in the text box nothing seems to happen. When I hit 'Enter' the PreviewTextInput event fires on the TreeView. The change does not propagate to the XML Document.
Is the binding I'm doing valid? Why is the data bound only one way?
Thanks for your help!
Bill