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>
    

      

     

  • 相关阅读:
    Flutter高仿微信项目开源-具即时通讯IM功能
    flutter 如何实现文件读写(使用篇)
    这是我的第一篇博客,测试文章
    对于ServiceManager的理解
    Class文件结构
    App进程的启动
    对于SystemServer的理解
    对于Zygote的理解
    Git内部原理浅析
    二叉搜索树(BST)基本操作
  • 原文地址:https://www.cnblogs.com/sliencer/p/3150521.html
Copyright © 2011-2022 走看看