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 ...
随机推荐
- redis中5种数据结构的使用
一.redis 数据结构使用场景 原来看过 redisbook 这本书,对 redis 的基本功能都已经熟悉了,从上周开始看 redis 的源码.目前目标是吃透 redis 的数据结构.我们都知道,在 ...
- 程氏CMS去掉静态页面的隐藏性版权方法
程氏CMS去掉静态页面的隐藏性版权方法 实例如图: 因为之前自己找了好久都没找到这俩代码写在那个文件夹的,经过跟csqq8讨论了也没有得到结果,今天突然发现,原来这些代码都经过base64加密,用加密 ...
- centos7重置root开机登录密码
今天忘记了centos7 root登录的密码,本来要好好的做个图文的教程也好啊,但是忘记截图什么的,就不在重复的工作了, 参考了下面的两个链接重置了密码,结合使用效果更好哦,嘿嘿.. 下次要是再遇到这 ...
- 关于解决form表单记录上次保存填写记录清空
传进来的是一个HTML的Table的ID. function doReset(tableId){ var tbl_content = document.getElementById(tableId); ...
- 浅谈 Data URI 与 BASE 64 编码
前言(废话):鼓捣 Stylish 的时候发现了这么个奇怪的代码行: Data:image/gif;BASE64,R0lGODlhEAAQAKEAAEKF9NPi/AAAAAAAACH5BAEAAAI ...
- C# 委托的几种写法
class Program { delegate string Get(string ss); delegate string Get2(int i); ...
- Sharepoint中出现webpart部署之后却找不到的一种情况
今天遇到了一个很奇怪的问题,明明代码没有任何问题,部署之后却没有找到添加的webpart,在(web Parts)Galleries中也找不到,最后才发现可能是和服务器的运行速度有关,就像之前遇到的问 ...
- arguments的用法
arguments 对象 在函数代码中,使用特殊对象 arguments,开发者无需明确指出参数名,就能访问它们. 例如,在函数 sayHi() 中,第一个参数是 message.用 argument ...
- inline-block总结
inline-block的内部表现类似block,可以设置宽高,外部表现类似inline,具有不还行的特性. 与float排版有些类似,当内部块级(可设置宽高),水平排列的时候都两者都可以实现. 两者 ...
- Nginx - Windows 环境安装 Nginx
1. 访问 http://nginx.org/en/download.html,下载 Windows 版本的安装包 2. 解压安装包,双击 nginx.exe,启动 nginx 3. 访问 http: ...