xaml

《深入浅出WPF》笔记——资源篇

若如初见. 提交于 2020-03-23 09:26:59
原文: 《深入浅出WPF》笔记——资源篇   前面的记录有的地方已经用到了资源,本文就来详细的记录一下WPF中的资源。我们平时的“资源”一词是指“资财之源”,是创造人类社会财富的源泉。在计算机程序中,只要是对程序有用的对象都可以统称资源。不过本文只记录WPF对象级资源和二进制资源。 一、WPF对象级资源的定义与查找   在WPF中,每一个界面元素都是一个对象,并且都有一个名为Resources的属性,这个属性继承于FrameworkElement类,其类型为ResourceDictionary。由于元素的属性名是复数形式,所以每一个对象可以拥有多个资源,由于资源的多样化,获取到的资源的类型为object类型,所以在获取到资源时,必要时要进行转化成符合自己要求的类型;由其类型可以知对象资源是以键值对的形式来存储的,当需要某个资源时,可以通过key索引来获取。下面看一个小实例: <Window x:Class="Chapter_08.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:sys="clr-namespace:System;assembly

《深入浅出WPF》笔记——绑定篇(二)

*爱你&永不变心* 提交于 2020-03-23 09:24:59
一、Binding对数据的校验与转化   在上一篇中有提到过绑定像是一座桥梁,在桥梁两端要有源和目标以及在桥梁上面我们可以设立关卡对数据进行验证,除此之外,源提供的数据有时不一定是目标想要的类型,但是可以通过转化成为目标需要的类型。 1.1Binding的数据验证   在软件设计过程中,数据的验证是经常要实现的。要实现Binding的数据验证,主要通过Binding的ValidationRoles属性来实现。下面让我们认识一下ValidationRoles(验证条件):可以看到ValidationRoles是复数形式,应该可以想到他是一个Collection<ValidationRole>类型的的属性,而ValidationRole是一个抽象类,所以我们要向验证条件集合里面添加的应该是继承自ValidationRole的一个实例,既然要继承抽象类,那么就要实现Validate方法,其形式为public abstract ValidationResult Validate(object value, CultureInfo cultureInfo),其中Value是要验证的值,cultureInfo暂不用理会,方法的返回值为ValidationResult类型的,Validate具有两个形参(一个是否通过验证,一个是错误信息)。为什么验证条件要用集合类型的呢

Blend 2015 教程 (四)控件模板

爱⌒轻易说出口 提交于 2020-03-23 06:16:30
前一篇讲述了修改ListBox样式的方法,本篇将修改性别显示区域的样式。 1. 选择ListBox控件,编辑ItemTemplate的当前项,选择CheckBox控件,在美工板导航栏中点击CheckBox,选择 编辑模板-创建空白项,进入控件模板编辑模式。 2. 选择文档大纲面板中的Grid,在属性面板中把Width改为30。 3. 在Grid中绘制一个TextBlock并重置布局,将Text属性改为男,HorizontalAlignment属性为居中对齐。 4. 在状态面板中点击Checked,如下图所示。 在属性面板中把Text属性改为女,文档大纲面板如下图,TextBlock下面有带五角星图标的Text属性,表示该属性有动画存在。 美工板如下图所示,红框表示正在录制动画。 此时运行程序可以看到效果,点击男或女文字可以进行切换。 5. 在文档大纲面板中选择Grid,在状态面板中选择基本,然后把Grid的Background改为蓝色。在状态面板中选择Checked,将背景色改为红色。可以看到Grid下加入了Background的动画。 可以运行程序试验效果。 6. 在状态面板中选择基本,在文档大纲面板中右键点击Grid,选择 分组-Grid。切换到资产面板,选择控件分类,拖动一个Border到文档大纲面板中的外层Grid中的内层Grid下方,如下图。

WPF 使用WavefrontObjLoader类显示obj格式的三维图元

与世无争的帅哥 提交于 2020-03-20 07:28:11
前言:毕业设计中需要用WPF展示三维图元,不适合使用XAML也不方便用Blend。于是在网上搜索相关内容找到一些资料,主要参考以下两位的博客: http://www.cnblogs.com/enjoyeclipse/archive/2012/03/21/2410439.html http://blog.sina.com.cn/s/blog_633d0e170100yte3.html 总结如下(18::2—20:00): 1.环境 :vs2010,使用pro/e生成的obj模型,网上下载的WavefrontObjLoader.cs代码(前面给出的第一个文章中有下载 http://www.cnblogs.com/enjoyeclipse/archive/2012/03/21/2410439.html )。 2.步骤:     vs2010中创建wpf项目,MainWindow.xaml的XAML代码如下 MainWindow。xaml 1 <Window x:Class="TestWpfObjLoader.MainWindow" 2 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 3 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 4

Change propety Canvas.Left and Canvas.Top in codebehind WinRT

泪湿孤枕 提交于 2020-03-18 11:30:36
问题 <Button x:Name="PlayButton" Content="Play" Canvas.Left="570" Canvas.Top="36" Height="51" Width="202" Background="#FF8898F9" /> How change Canvas.Top and Canvas.Left property of PlayButton in the code? 回答1: Canvas class has SetTop and SetLeft static methods that set these attached properties: Canvas.SetTop(PlayButton, 36); Canvas.SetLeft(PlayButton, 750); 回答2: Canvas.SetLeft(PlayButton, 100); Canvas.SetTop(PlayButton, 50); 来源: https://stackoverflow.com/questions/21515135/change-propety-canvas

Change propety Canvas.Left and Canvas.Top in codebehind WinRT

独自空忆成欢 提交于 2020-03-18 11:30:14
问题 <Button x:Name="PlayButton" Content="Play" Canvas.Left="570" Canvas.Top="36" Height="51" Width="202" Background="#FF8898F9" /> How change Canvas.Top and Canvas.Left property of PlayButton in the code? 回答1: Canvas class has SetTop and SetLeft static methods that set these attached properties: Canvas.SetTop(PlayButton, 36); Canvas.SetLeft(PlayButton, 750); 回答2: Canvas.SetLeft(PlayButton, 100); Canvas.SetTop(PlayButton, 50); 来源: https://stackoverflow.com/questions/21515135/change-propety-canvas

Specify transparency level of a named color in XAML

末鹿安然 提交于 2020-03-18 10:43:42
问题 Is there a way in XAML to create a color object from a named color with different custom transparency level? e.g. <Label Background="{SkyBlue;220}" /> I know this doesn't work, but just wanted to quote an example. 回答1: One of those times when you find the answer yourself. Here's the correct way for any future reader: <Label.Background> <SolidColorBrush Color="SkyBlue" Opacity=".9" /> </Label.Background> Opacity ranges between 0 and 1, 1 being full opaque (non-transparent). Edit Regarding @Dai

XAML DataContext DesignInstance with nested types

你说的曾经没有我的故事 提交于 2020-03-15 06:29:28
问题 Is it possible to specify a nested type for d:DesignInstance in XAML? And if so, how? If I have the following class structure: namespace MyApp { public class OuterClass { public class InnerClass { public string SomeData {get;set;} } } } How can I use the InnerClass type as a DesignInstance? The following doesn't work: <phone:PhoneApplicationPage ... xmlns:local="clr-namespace:MyApp" ... d:DataContext="{d:DesignInstance Type=local:OuterClass.InnerClass}" > 回答1: Try changing . to + . Something

How to make an ellipse follow a curve on a canvas

你说的曾经没有我的故事 提交于 2020-03-15 05:47:32
问题 I am having an issue trying to get an ellipse to properly follow a path on my canvas. I supposed the problem stems from the fact that my mini syntax defines movement between x and y values but am targeting only one of those values in my target property (e.g. ( Canvas.Top or Canvas.Left ). I can not seem to find any attached "Position" property on the canvas that would take in a Position type which would work with my path. What would be the proper way to get this path to work? <Canvas Name=

WPF: Animating along path geometry

牧云@^-^@ 提交于 2020-03-14 18:21:49
问题 I am dealing with the following issue for a week now. Please, bear with me as I explain. What I am trying to achive is, for some of us, pretty simple, but being new to WPF makes things hard. The image above was rendered by converting (already had) svg to xaml and afterwards importing it to Visual Studio. This is what the xaml looks like. <Canvas x:Name="Main" Margin="158,-223,-148,233"> <Canvas.RenderTransform> <MatrixTransform Matrix="1.25 0 0 -1.25 -197.1231 961.58875"/> </Canvas