网站构建工具,怎么做网站演示,网站开发中怎么设置快捷键,品牌营销策划方案怎么写《深入浅出WPF》读书笔记.4名称空间详解
背景
主要讲明名称空间概念#xff0c;可以理解为命名空间的引用。
xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml
#x1f446;如x可以理解为一些列命名空间的引用。
不一一列举#xff0c;只讲几个特殊的…《深入浅出WPF》读书笔记.4名称空间详解
背景
主要讲明名称空间概念可以理解为命名空间的引用。
xmlns:xhttp://schemas.microsoft.com/winfx/2006/xaml
如x可以理解为一些列命名空间的引用。
不一一列举只讲几个特殊的名称空间x:Type x:Null x:Data x:Code
代码
x:Type
指定数据类型
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;namespace WpfBookDemo
{public class MyButton:Button{public Type UserWindowType { get; set; }protected override void OnClick(){base.OnClick();Window winActivator.CreateInstance(this.UserWindowType) as Window;if(win is not null){win.Show();}}}
}Window x:ClassWpfBookDemo.MyWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfBookDemomc:IgnorabledTitleMyWindow Height300 Width300 GridStackPanel VerticalAlignmentCenterTextBox Width120 BackgroundLightGreen Margin5/TextBoxTextBox Width120 BackgroundLightGreen Margin5/TextBoxTextBox Width120 BackgroundLightGreen Margin5/TextBoxButton Width120 BackgroundLightGreen Content点击一下 Margin5/Button/StackPanel/Grid
/WindowWindow x:ClassWpfBookDemo.xTypeDemoxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfBookDemomc:IgnorabledTitlexTypeDemo Height450 Width800Gridlocal:MyButton x:Namembtn Content点击一下 Width120 Height40UserWindowType{x:Type local:MyWindow}/local:MyButton/Grid
/Windowx:Null
为属性设置空值
Window x:ClassWpfBookDemo.xNullDemoxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfBookDemomc:IgnorabledTitlexNullDemo Height450 Width300Window.ResourcesStyle x:Key{x:Type Button} TargetType{x:Type Button}Setter PropertyWidth Value60/SetterSetter PropertyHeight Value36/SetterSetter PropertyMargin Value5/Setter/Style/Window.ResourcesGridStackPanel VerticalAlignmentCenterButton/ButtonButton /ButtonButton /ButtonButton Style{x:Null} Content没有样式/Button/StackPanel/Grid
/Windowx:Data
数据提供者
Window x:ClassWpfBookDemo.xDataDemoxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfBookDemomc:IgnorabledTitlexDataDemo Height200 Width300Window.ResourcesXmlDataProvider x:KeyInventoryData XPathFruitsx:XData xmlnsFruits Fruit NameAppleApple/FruitFruit NameBananaBanana/FruitFruit NameOrangeOrange/Fruit/Fruits/x:XData/XmlDataProvider/Window.ResourcesGridStackPanel VerticalAlignmentCenter Height150ListBox ItemsSource{Binding Source{StaticResource InventoryData}, XPathFruit}/ListBox/StackPanel/Grid
/Windowx:Code
可以将后端代码挪到xam中
Window x:ClassWpfBookDemo.xCodeDemoxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:WpfBookDemomc:IgnorabledTitlexCodeDemo Height450 Width800GridStackPanel VerticalAlignmentCenter HorizontalAlignmentCenterButton x:Namebtn Content点击一下 Clickbtn_Click Width120 Height40/Button/StackPanel/Gridx:Code![CDATA[private void btn_Click(object sender, RoutedEventArgs e){MessageBox.Show(使用x:Code可以将后端代码挪动到前端);}]]/x:Code
/Window不想写代码只想干黑悟空但是菜