WPF系列
一、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系列的更多相关文章
- [WPF系列]-数据邦定之DataTemplate 对分层数据的支持
到目前为止,我们仅讨论如何绑定和显示单个集合. 某些时候,您要绑定的集合包含其他集合. HierarchicalDataTemplate 类专用于 HeaderedItemsControl 类型以显示 ...
- [WPF系列]-数据邦定之DataTemplate 根据对象属性切换模板
引言 书接上回[WPF系列-数据邦定之DataTemplate],本篇介绍如何根据属性切换模板(DataTemplate) 切换模板的两种方式: 使用DataTemplateSelecto ...
- [WPF系列]-TreeView的常用事项
引言 项目经常会用Treeview来组织一些具有层级结构的数据,本节就将项目使用Treeview常见的问题作一个总结. DataBinding数据绑定 DataTemplate自定义 <Hier ...
- [WPF系列]从基础起步学习系列计划
引言 WPF技术已经算不什么新技术,一搜一大把关于WPF基础甚至高级的内容.之前工作中一直使用winform所以一直没有深入学习WPF,这次因项目中使用了WPF技术来实现比较酷的展示界面.我在这里只是 ...
- WPF系列教程——(三)使用Win10 Edge浏览器内核 - 简书
原文:WPF系列教程--(三)使用Win10 Edge浏览器内核 - 简书 在需要显示一些 H5网站的时候自带的WebBrowser总是显示不了,WebBrowser使用的是IE内核,许多H5新特性都 ...
- WPF系列教程——(一)仿TIM QQ界面 - 简书
原文:WPF系列教程--(一)仿TIM QQ界面 - 简书 TIM QQ 我们先来看一下TIM QQ长什么样,整体可以将界面分为三个部分 TIM QQ 1. 准备 阅读本文假设你已经有XAML布局的基 ...
- WPF系列教程——(二)使用Prism实现MVVM设计模式 - 简书
原文:WPF系列教程--(二)使用Prism实现MVVM设计模式 - 简书 本文假设你已经知道MVVM设计模式是什么,所以直接进入正题,今天我们就用Prism来实现WPF的MVVM设计模式,百度上关于 ...
- WPF系列 —— 控件添加依赖属性(转)
WPF系列 —— 控件添加依赖属性 依赖属性的概念,用途 ,如何新建与使用.本文用做一个自定义TimePicker控件来演示WPF的依赖属性的简单应用. 先上TimePicker的一个效果图. 概念 ...
- 深入浅出WPF-02.WPF系列目录
WPF系列目录 2. XAML认识 3. XAML语法 4. x名称空间详解 5. 控件与布局 6. 绑定Binding-01 6. 绑定Binding-02 6. 绑定Binding-03 7. 属 ...
- WPF系列:样式
一般简单的样式我们可以直接写在控件中 <Button Canvas.Left="20" Canvas.Top="30" Width="100&q ...
随机推荐
- CentOS(六)--Linux系统的网络环境配置
Linux系统下的网络环境配置,Linux.Unix就是网络的世界,所以在Linux系统中如何配置网络环境变量是至关重要的,这里将会给出3种Linux系统下网络环境配置的方法! 在配置网络环境之前,首 ...
- Eclipse输入任意字母或指定字符出现提示框
Eclipse默认是输入"."的时候会有提示框提示对应的API. 如果想更方便的输入任意字母或者指定的符号出现提示框设置如下: 打开Eclipse,选中“Window”->& ...
- 【线性结构上的动态规划】UVa 11400 - Lighting System Design
Problem F Lighting System Design Input: Standard Input Output: Standard Output You are given the tas ...
- CSS3秘笈第三版涵盖HTML5学习笔记9~12章
第9章,装饰网站导航 限制访问,处于隐私方面考虑,浏览器已经开始限制可以对伪类:visited应用哪些CSS属性了.其中包括对已访问过的链接定义color.background-color.borde ...
- struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input
原文地址:struts2 jsp表单提交后保留表单中输入框中的值 下拉框select与input jsp页面 1 function dosearch() {2 if ($(&q ...
- Quartz Scheduler(2.2.1) - Usage of CronTriggers
Cron is a UNIX tool that has been around for a long time, so its scheduling capabilities are powerfu ...
- C#性能优化实践
性能主要指两个方面:内存消耗和执行速度.性能优化简而言之,就是在不影响系统运行正确性的前提下,使之运行地更快,完成特定功能所需的时间更短. 本文以.NET平台下的控件产品MultiRow为例,描述C# ...
- 备忘====[HttpPost]和[AcceptVerbs(HttpVerbs.Post)]区别
1.共同点:[HttpPost]和[AcceptVerbs(HttpVerbs.Post)]都是只接受POST请求过来的数据. 2.不同点:在MVC中如果想一个action既可以回应POST请求也可以 ...
- 忍者无敌-实例讲解Cocos2d-x瓦片地图
实例比较简单,如图所示,地图上有一个忍者精灵,玩家点击他周围的上.下.左.右,他能够向这个方向行走.当他遇到障碍物后是无法穿越的,障碍物是除了草地以为部分,包括了:树.山.河流等. 忍者实例地图(TO ...
- Swift标识符和关键字
任何一种计算机语言都离不开标识符和关键字,下面我们将详细介绍Swift标识符和关键字. 标示符 标识符就是给变量.常量.方法.函数.枚举.结构体.类.协议等指定的名字.构成标识符的字母均有一定的规范, ...