文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Windows Mobile TreeView从xml文件中加载数据

Windows Mobile TreeView从xml文件中加载数据

时间:2010-09-28  来源:永恒的记忆

  在这篇文章中,我建议使用TreeView控件使用XML文件来管理应用程序设置的耦合。 The following screenshots show the component in action.下面的截图显示了在行动的组成部分。

  下面是截图

 

  TreeView的重要属性及方法、事件介绍

  1.Nodes:分配给树视图控件的树节点

  2.SelectedNode: 当前在树视图控件中选定的 System.Windows.Forms.TreeNode

  3。CollapseAll()折叠所有树节点

  4. ExpandAll()展开所有树节点

  5.OnAfterSelect主要的事件 包含事件数据的 System.Windows.Forms.TreeViewEventArgs

一个XML文件的例子如下:

<?xml version="1.0" encoding="utf-8" ?>
<options>
  <group name="General">
    <option name="TimeZone" displayName="Time zone">
      <value name="EST" selected="true" />
      <value name="CST" />
      <value name="MST" />
      <value name="PST" />
    </option>
    <option name="UpdateInterval" displayName="Update interval">
      <value name="10" displayName="10 sec" />
      <value name="30" displayName="30 sec" selected="true" />
      <value name="60" displayName="1 min" />
      <value name="300" displayName="5 min" />
      <value name="600" displayName="10 min" />
    </option>
    <option name="CacheSize" displayName="Cache size">
      <value name="32" displayName="32 MB" selected="true" />
      <value name="64" displayName="64 MB" />
      <value name="128" displayName="128 MB" />
    </option>
    <option name="CheckInterval" displayName="Check for app update">
      <value name="0" displayName="Every time app starts" selected="true" />
      <value name="1" displayName="Every day" />
      <value name="7" displayName="Every week" />
      <value name="30" displayName="Every month" />
      <value name="365" displayName="Every year" />
    </option>
  </group>
  <group name="Appearance">
    <option name="Skin">
      <value name="Classic" selected="true" />
      <value name="IceFusion" displayName="Ice Fusion" />
      <value name="Monochrome" />
    </option>
    <option name="ShowToolbar" displayName="Show toolbar">
      <value name="true" selected="true" />
      <value name="false" />
    </option>
    <option name="ShowStatusBar" displayName="Show status bar">
      <value name="true" selected="true" />
      <value name="false" />
    </option>
  </group>
  <group name="SecurityPrivacy" displayName="Security &amp; Privacy">
    <option name="EnablePassword" displayName="Enable password protection">
      <value name="true" selected="true" />
      <value name="false" />
    </option>
    <group name="SharedContents" displayName="Shared contents">
      <option name="ContactInfo" displayName="Contact info">
        <value name="true" />
        <value name="false" selected="true" />
      </option>
      <option name="Photos">
        <value name="true" selected="true" />
        <value name="false" />
      </option>
      <option name="Posts">
        <value name="true" selected="true" />
        <value name="false" />
      </option>
    </group> 
  </group>
</options>

大约有这个XML一些规则。

  • Each node type has a name and a displayName attributes. name , which is required, is used or referenced in our program. displayName , which is optional, is used in the TreeView for presentation.每个节点类型都有一个name和一个displayName属性。 name ,这是必需的,是用来或程序中引用的。 displayName ,这是可选的,是树视图中使用的演示文稿。 If a displayName is missing, the corresponding name is used for presentation.如果displayName丢失,相应的name是用于演示。
  • group can contain zero or more option nodes and group nodes (or subgroups). group可以包含零个或多个option节点和group节点(或小组)。 We can have as many levels of embedded group nodes as we want.我们可以有许多层次的嵌入式group节点,我们想要的。
  • option must only contain one or more value nodes. option必须只包含一个或多个value的节点。
  • Only one of the multiple value nodes of an option can have a selected attribute of "true", indicating that it is the current value of the option .只有多个之一value一节点的option可以有一个selected “属性”真,这表明它是当前value的option 。

From programming point of view, using such an XML as data store for our Options component has these advantages:从编程的角度来看作为我们的选择组件的数据存储一个XML等,具有以下优点:

  • Both XML and TreeView are based on tree structure. XML和TreeView的是基于树结构。 One for storage and one for presentation.一个用于存储和表现之一。 This perfect match makes programming easy.这个完美的配合使得编程容易。
  • Organizing options in groups and subgroups is inherently supported.在选项组和子组组织本质上是支持的。
  • It makes it easy to manage both the selected values and all the available values.它可以轻松地同时管理的价值观和选择所有可用的值。 With the traditional Settings file, only selected values are persisted, whileas the available values are either in a separate resource file or hard-coded in the program.随着文件的传统设置,只有选择的值是坚持,whileas可用的值可以是一个单独的资源文件或硬编码在程序中。
  • To a certain extent we can change the options without having to recompile our program.在一定程度上,我们可以改变我们,而不必重新编译程序的选项。 It is also possible to update the XML remotely.它也可以更新XML远程。
  • It makes localization easy.它使本地化容易。 Just translate all the displayName attributes to different languages.刚刚翻译所有displayName属性不同的语言。

  下面是步骤

  1.创建options.xml并以此作为嵌入的资源。

  2.添加Windows窗体,到 OptionsForm项目 这将是我们的选择对话框。

  

  • Add a TreeView control and the following four menu items or buttons to the OptionsForm :添加一个TreeView控件和以下四个菜单项或按钮到OptionsForm :
    • 确定- 保存更改选项并关闭选项对话框
    • 取消 - 取消更改选项并关闭选项对话框
    • 默认 - 还原的选项为默认值(如在嵌入资源存储的Options.xml指定)
    • 编辑 - 相应变动期权的价值的价值表示了TreeView选择光标
  • 源码下载

    相关阅读 更多 +
    排行榜 更多 +
    辰域智控app

    辰域智控app

    系统工具 下载
    网医联盟app

    网医联盟app

    运动健身 下载
    汇丰汇选App

    汇丰汇选App

    金融理财 下载