zoukankan      html  css  js  c++  java
  • 玩一个:可以显示任何xml树结构的xaml定义

    学习中, 玩一玩。 效果如下。Xaml随后。   

    <Page
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:y="clr-namespace:System.Xml;assembly=system.xml"  
      >
      <Page.Resources>
        <XmlDataProvider x:Key="xdata" Source="C:devUpgradeLog.XML">
        </XmlDataProvider>
        <HierarchicalDataTemplate x:Key="h1" ItemsSource="{Binding XPath=node()|@*}" >
          <StackPanel Orientation="Horizontal">
          <StackPanel x:Name="attrib" Visibility="Collapsed" Orientation="Horizontal">
            <TextBlock Text="@"/>
            <TextBlock Text="{Binding Path=Name}"/>
            <TextBlock Text="='"/>
            <TextBlock Text="{Binding Path=Value}"/>
            <TextBlock Text="'"/>
          </StackPanel>
          <StackPanel x:Name="ele" Visibility="Collapsed" Orientation="Horizontal">
            <TextBlock Text="{Binding Path=Name}"/>
            <TextBlock Text=" ChildCount="/>
            <TextBlock Text="{Binding Path=ChildNodes.Count}"/>
          </StackPanel>
          <StackPanel x:Name="txt" Visibility="Collapsed" Orientation="Horizontal">
            <TextBlock Text="Text()="/>
            <TextBlock Text="{Binding XPath=.}"/>
          </StackPanel>
          <StackPanel x:Name="comment" Visibility="Collapsed" Orientation="Horizontal">
            <TextBlock Text="comment()="/>
            <TextBlock Text="{Binding Path=InnerText}"/>
          </StackPanel>
          <StackPanel x:Name="pi" Visibility="Collapsed" Orientation="Horizontal">
            <TextBlock Text="pi="/>
            <TextBlock Text="{Binding Path=Name}"/>
          </StackPanel>
          </StackPanel>
          <HierarchicalDataTemplate.Triggers>
            <DataTrigger Binding="{Binding Path=NodeType}" Value="Attribute">
             <Setter  TargetName="attrib" Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=NodeType}" Value="Element">
             <Setter  TargetName="ele" Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=NodeType}" Value="Text">
             <Setter  TargetName="txt" Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=NodeType}" Value="CDATA">
             <Setter  TargetName="txt" Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=NodeType}" Value="Comment">
             <Setter  TargetName="comment" Property="Visibility" Value="Visible"/>
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=NodeType}" Value="ProcessingInstruction">
             <Setter  TargetName="pi" Property="Visibility" Value="Visible"/>
            </DataTrigger>
          </HierarchicalDataTemplate.Triggers>
        </HierarchicalDataTemplate>
      </Page.Resources>
      <Grid>  
      <Grid.RowDefinitions>
      <RowDefinition/>
      </Grid.RowDefinitions>
      <TreeView Grid.Row="0" DataContext="{StaticResource xdata}" ItemsSource="{Binding XPath=/node()}" ItemTemplate="{StaticResource h1}"  >
      </TreeView>
      </Grid>
    </Page>
    

      

     

  • 相关阅读:
    2014年第五届蓝桥杯省赛试题(JavaA组)
    2013年第四届蓝桥杯省赛试题(JavaA组)
    2013蓝桥杯JavaA组T10 大臣的旅费(树的直径)
    CodeForces
    天梯赛 L2-006 树的遍历(序列建树)
    PAT甲 1095 解码PAT准考证/1153 Decode Registration Card of PAT(优化技巧)
    2015年第六届蓝桥杯省赛T10 生命之树(树形dp+Java模拟vector)
    ZOJ
    SPOJ
    HDU
  • 原文地址:https://www.cnblogs.com/sliencer/p/3150521.html
Copyright © 2011-2022 走看看