一、ListView绑定数据源XML

 //前端代码
1 <Window x:Class="ListView读取XML数据.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow"
Height="350" Width="525">
<Window.Resources>
<XmlDataProvider x:Key="Student" Source="Book.xml">
</XmlDataProvider>

</Window.Resources>
<Grid>
<ListView ItemsSource="{Binding Source={StaticResource Student},XPath=/Person/Information}">
</ListView>
</Grid>
</Window>
 //XML文件
1 <?xml version="1.0" encoding="utf-8" ?>
<Person>
<Information>
<Name>张三</Name>
<Age>22</Age>
<Sex>男</Sex>
</Information>
<Information>
<Name>李四</Name>
<Age>25</Age>
<Sex>男</Sex>
</Information>
</Person>
//效果截图


二、保存数据到XML

             XmlDocument xml = new XmlDocument();
string str_path = @"J:\WPF\test\XMLData.xml";
XmlNode root = null;
if (File.Exists(str_path))
{
xml.Load(str_path);
root = xml.SelectSingleNode("Person");
} XmlNodeList nodelist = xml.SelectNodes("/Person/Student/Infor");
XmlElement inf,adr, stu, info, UN, IP, DB;
bool bl_exist = true;
foreach (XmlNode node in nodelist)
{
if (node.ChildNodes[].InnerText == (ServerName.Text + ".").ToString() &&
node.ChildNodes[].InnerText == (UserName.Text + ".").ToString() &&
node.ChildNodes[].InnerText ==DataName.Text)
{
bl_exist = false;
break;
}
}
if (bl_exist)
{
stu = xml.CreateElement("Student"); //创建元素
info = xml.CreateElement("Infor");
UN = xml.CreateElement("UserName");
IP = xml.CreateElement("IP");
DB = xml.CreateElement("DataBaseName"); inf = xml.CreateElement("Information");
adr = xml.CreateElement("Address");
adr.InnerText = (UserName.Text + "." + ServerName.Text + "." + DataName.Text).ToString();
root.AppendChild(inf);
inf.AppendChild(adr); UN.InnerText = (UserName.Text + ".").ToString();
IP.InnerText = (ServerName.Text + ".").ToString();
DB.InnerText = DataName.Text;
stu.AppendChild(info);
info.AppendChild(UN);
info.AppendChild(IP);
info.AppendChild(DB);
root.AppendChild(stu);
MessageBox.Show("数据保存成功");
}
xml.Save(str_path);

三、页面切换出现淡入淡出效果和图表控件页面重新加载动画

1、把Window窗口改为NavigationWindow导航切换窗口,添加源文件Market.xaml
<NavigationWindow x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="1080" Width="3840" WindowState="Maximized" Source="Market.xaml" WindowStyle="None" ShowsNavigationUI="False" ResizeMode="NoResize" Navigating="NavigationWindow_Navigating"
MouseLeftButtonDown="NavigationWindow_MouseLeftButtonDown">
</NavigationWindow> 2、下一个页面切换的时候用以下代码就可实现:
NavigationService.Navigate(new Uri("Power.xaml", UriKind.Relative)); 3、淡入淡出效果
        private void NavigationWindow_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (Content != null && !_allowDirectNavigation)
{
e.Cancel = true;
_navArgs = e;
this.IsHitTestVisible = false;
DoubleAnimation da = new DoubleAnimation(0.3d, new Duration(TimeSpan.FromMilliseconds()));
da.Completed += FadeOutCompleted;
this.BeginAnimation(OpacityProperty, da);
}
_allowDirectNavigation = false;
}
private void FadeOutCompleted(object sender, EventArgs e)
{
(sender as AnimationClock).Completed -= FadeOutCompleted; this.IsHitTestVisible = true; _allowDirectNavigation = true;
switch (_navArgs.NavigationMode)
{
case NavigationMode.New:
if (_navArgs.Uri == null)
{
NavigationService.Navigate(_navArgs.Content);
}
else
{
NavigationService.Navigate(_navArgs.Uri);
}
break;
case NavigationMode.Back:
NavigationService.GoBack();
break; case NavigationMode.Forward:
NavigationService.GoForward();
break;
case NavigationMode.Refresh:
NavigationService.Refresh();
break;
} Dispatcher.BeginInvoke(DispatcherPriority.Loaded,
(ThreadStart)delegate()
{
DoubleAnimation da = new DoubleAnimation(1.0d, new Duration(TimeSpan.FromMilliseconds()));
this.BeginAnimation(OpacityProperty, da);
});
}
private bool _allowDirectNavigation = false;
private NavigatingCancelEventArgs _navArgs = null;

WPF系列的更多相关文章

  1. [WPF系列]-数据邦定之DataTemplate 对分层数据的支持

    到目前为止,我们仅讨论如何绑定和显示单个集合. 某些时候,您要绑定的集合包含其他集合. HierarchicalDataTemplate 类专用于 HeaderedItemsControl 类型以显示 ...

  2. [WPF系列]-数据邦定之DataTemplate 根据对象属性切换模板

      引言 书接上回[WPF系列-数据邦定之DataTemplate],本篇介绍如何根据属性切换模板(DataTemplate)   切换模板的两种方式:   使用DataTemplateSelecto ...

  3. [WPF系列]-TreeView的常用事项

    引言 项目经常会用Treeview来组织一些具有层级结构的数据,本节就将项目使用Treeview常见的问题作一个总结. DataBinding数据绑定 DataTemplate自定义 <Hier ...

  4. [WPF系列]从基础起步学习系列计划

    引言 WPF技术已经算不什么新技术,一搜一大把关于WPF基础甚至高级的内容.之前工作中一直使用winform所以一直没有深入学习WPF,这次因项目中使用了WPF技术来实现比较酷的展示界面.我在这里只是 ...

  5. WPF系列教程——(三)使用Win10 Edge浏览器内核 - 简书

    原文:WPF系列教程--(三)使用Win10 Edge浏览器内核 - 简书 在需要显示一些 H5网站的时候自带的WebBrowser总是显示不了,WebBrowser使用的是IE内核,许多H5新特性都 ...

  6. WPF系列教程——(一)仿TIM QQ界面 - 简书

    原文:WPF系列教程--(一)仿TIM QQ界面 - 简书 TIM QQ 我们先来看一下TIM QQ长什么样,整体可以将界面分为三个部分 TIM QQ 1. 准备 阅读本文假设你已经有XAML布局的基 ...

  7. WPF系列教程——(二)使用Prism实现MVVM设计模式 - 简书

    原文:WPF系列教程--(二)使用Prism实现MVVM设计模式 - 简书 本文假设你已经知道MVVM设计模式是什么,所以直接进入正题,今天我们就用Prism来实现WPF的MVVM设计模式,百度上关于 ...

  8. WPF系列 —— 控件添加依赖属性(转)

    WPF系列 —— 控件添加依赖属性 依赖属性的概念,用途 ,如何新建与使用.本文用做一个自定义TimePicker控件来演示WPF的依赖属性的简单应用. 先上TimePicker的一个效果图. 概念 ...

  9. 深入浅出WPF-02.WPF系列目录

    WPF系列目录 2. XAML认识 3. XAML语法 4. x名称空间详解 5. 控件与布局 6. 绑定Binding-01 6. 绑定Binding-02 6. 绑定Binding-03 7. 属 ...

  10. WPF系列:样式

    一般简单的样式我们可以直接写在控件中 <Button Canvas.Left="20" Canvas.Top="30" Width="100&q ...

随机推荐

  1. python 元类——metaclass

    from stack overflow:http://stackoverflow.com/questions/100003/what-is-a-metaclass-in-python Classes ...

  2. [改善Java代码]适时选择getDeclaredxxx和getxxx

    Java的Class类提供了很多的getDeclaredxxx方法和getxxx方法,例如getDeclaredmethod和getMethod成对出现,getDeclaredConstructors ...

  3. [未完成]关于POI的使用

    关于POI的使用关于POI的使用关于POI的使用关于POI的使用

  4. Leetcode 9. Palindrome Number(判断回文数字)

    Determine whether an integer is a palindrome. Do this without extra space.(不要使用额外的空间) Some hints: Co ...

  5. ZooKeeper(3.4.5) - 开源客户端 Curator(2.7.0) 的简单示例

    一.创建会话 1. 创建会话 package com.huey.dream.demo; import org.apache.curator.framework.CuratorFramework; im ...

  6. C#操作Excel数据增删改查示例

    Excel数据增删改查我们可以使用c#进行操作,首先创建ExcelDB.xlsx文件,并添加两张工作表,接下按照下面的操作步骤即可 C#操作Excel数据增删改查. 首先创建ExcelDB.xlsx文 ...

  7. JQGrid各种参数详解API(转载)

    下面是转自其他人blog的一个学习资料,与其说是学习资料,说成查询帮助文档更加合适. jqGrid学习之 ------------- 安装 jqGrid安装很简单,只需把相应的css.js文件加入到页 ...

  8. 个人常用jq方法复习

    $("#elem").on({ mouseover:function(){}, mouseout:function(){}, }); $(ele).closest("di ...

  9. apktool反编译工具

    几个报错的解决办法 apktool反编译时经常会出现下面的信息 Input file was not found or was not readable. Destination directory ...

  10. MAC系统介绍

    MACOS: UNIX系统图形界面的显示 开发环境: 一种是终端(terminal) 一种是Xcode(ide) MAC快捷键: command(window) + c : 复制 command + ...