Click here to Skip to main content
15,887,962 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
this my xml file format:
XML
<props>
  <specific_criteria>NONE</specific_criteria>
  <specific_condition>NEW</specific_condition>
  <specific_disposition>
    <disposition>NONE</disposition>
  </specific_disposition>
  <specific_model>NONE</specific_model>
  <specific_velocity>NONE</specific_velocity>
  <specific_cons_model>NONE</specific_cons_model>
  <specific_program>
    <program>NONE</program>
  </specific_program>
  <specific_operation>NONE</specific_operation>
  <specific_oem>NONE</specific_oem>
  <specific_esn_status />
  <special_criteria />
  <same_disposition>N</same_disposition>
  <same_model>N</same_model>
  <same_sku>N</same_sku>
  <same_esn_status>N</same_esn_status>
  <same_cons_model>N</same_cons_model>
  <same_condition>N</same_condition>
  <same_velocity>N</same_velocity>
  <same_receipt>N</same_receipt>
  <same_oem>N</same_oem>
</props>

i need to show in treeview and also editiable mode in node values in wpf using mvvm
Posted
Updated 28-Dec-15 6:42am
v2
Comments
Akki Challa 29-Dec-15 5:05am    
I am able to show xml in treeview but unable to edit treeview nodes. my xaml as below.

<hierarchicaldatatemplate x:key="NodeTemplate">
<textblock x:name="tb">
<!--<textblock x:name="tb">-->
<!--<textbox datacontext="{Binding ScreenXML}" x:name="tb" isreadonly="True">-->
<hierarchicaldatatemplate.itemssource>
<binding xpath="child::node()">

<hierarchicaldatatemplate.triggers>
<datatrigger binding="{Binding Path=NodeType}" value="Text">
<setter targetname="tb" property="Text" value="{Binding Path=Value}">

<datatrigger binding="{Binding Path=NodeType}" value="Element">
<setter targetname="tb" property="Text" value="{Binding Path=Name}">



<dockpanel grid.row="1">
<TreeView Name="tv" ItemTemplate= "{StaticResource NodeTemplate}" ItemsSource="{Binding ScreenXML}" FontWeight="Bold" AoViews:Attached.TreeViewSelectedItem="{Binding SelectedArea, Mode=TwoWay}" >
</TreeView>

now i need to edit treeview nodes or values.

You need to add a data template with a textbox in it as shown below :

C#
<TreeView x:Name="MyTreeView">
           <TreeView.Resources>
               <DataTemplate x:Key="NormalTemplate">
                   <StackPanel Orientation="Horizontal">
                       <TextBlock Text="{Binding ID}" Margin="3"/>
                       <TextBlock Text="-" Margin="3"/>
                       <TextBlock Text="{Binding Name}" Margin="3"/>
                   </StackPanel>
               </DataTemplate>
               <DataTemplate x:Key="EditTemplate">
                   <TextBox Text="{Binding Name}"/>
               </DataTemplate>
           </TreeView.Resources>
           <TreeView.ItemTemplate>
               <HierarchicalDataTemplate
                            ItemsSource="{Binding Team}">
                   <ContentPresenter Content="{Binding}">
                       <ContentPresenter.Style>
                           <Style TargetType="{x:Type ContentPresenter}">
                               <Setter Property="ContentTemplate"
                                       Value="{StaticResource
                                               NormalTemplate}"/>
                               <Style.Triggers>
                                   <DataTrigger
                                        Binding="{Binding IsSelected,
                                        RelativeSource={RelativeSource
                                             FindAncestor,
                                        AncestorType={x:Type TreeViewItem}}}"
                                             Value="True">
                                       <Setter Property="ContentTemplate"
                                               Value="{StaticResource
                                                       EditTemplate}" />
                                   </DataTrigger>
                               </Style.Triggers>
                           </Style>
                       </ContentPresenter.Style>
                   </ContentPresenter>
               </HierarchicalDataTemplate>
           </TreeView.ItemTemplate>
       </TreeView>



Do let me know it this helped !!!
Full source : SOURCE
 
Share this answer
 
v5
i am able to populate as shown xml in tree view but i need to edit tag values like NONE,NEW,NONE,NONE,NONE,NONE,NONE AND ETC USING WPF WITH MVVM. HELP ME ASAP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900