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 ...
随机推荐
- Mysql:表的操作
1.列的添加 2.列的删除 删除多列只需在DROP id 后加, DROP column_name; 3.显示表属性 4.设置默认值 5.删除默认值
- [改善Java代码]线程优先级只使用三个等级
线程的优先级(priority)决定了线程获得CPU运行的机会,优先级越高获得的运行机会越大,优先级越低获得的机会越小.Java的线程有10个级别(准确的说是11个级别,级别为0的线程是JVM,应用程 ...
- ubuntu下安装Sublime Text并支持中文输入
Sublime Text还是文本编辑器中比较不错的,就是他的文件对比有些差劲吧,还有中文输入需要打补丁,不知道开发者是怎么想的... 当然,这个软件是收费的,但是不买也能一直的使用,在我天朝就这点好处 ...
- poj 2749 2-SAT问题
思路:首先将hate和friend建边求其次2-SAT问题,判断是否能有解,没解就输出-1,否则用二分枚举最大的长度,将两个barn的距离小于mid的看做是矛盾,然后建边,求2-SAT问题.找出最优解 ...
- HttpClient(4.3.5) - HTTP Header
An HTTP message can contain a number of headers describing properties of the message such as the con ...
- jQuery 笔记
1. 选择器 http://www.runoob.com/jquery/jquery-selectors.html 2. toggle() 用来切换 hide() 和 show() 方法 ht ...
- CSS常见的浏览器前缀
为了让浏览器识别某些专属属性,有时候需要在CSS属性前增加浏览器前缀 -ms-:Microsoft IE -moz-:Mozilla Firefox -o-:Opera Opera -webkit-: ...
- ajax — get? or post?
ajax - get? or post? 与 POST 相比,GET 更简单也更快,并且在大部分情况下都能用. 然而,在以下情况中,请使用 POST 请求: 无法使用缓存文件(更新服务器上的文件或数据 ...
- 【译】在JavaScript中{}+{}的结果是什么?
原文链接:What is {} + {} in JavaScript? 最近,Gary Bernhardt在一个名为'Wat'的闪电演讲中提到了一些有趣的JavaScript技巧.当你把一个objec ...
- URAL 1024 Permutations(LCM)
题意:已知,可得出 P(1) = 4, P(2) = 1, P(3) = 5,由此可得出 P(P(1)) = P(4) = 2. And P(P(3)) = P(5) = 3,因此.经过k次如上变换, ...