热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

WPF调用模板

WPF调用模板前台代码

WPF调用模板
在这里插入图片描述
前台代码

<Window x:Class&#61;"Target.MainWindow"xmlns&#61;"http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x&#61;"http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d&#61;"http://schemas.microsoft.com/expression/blend/2008"xmlns:mc&#61;"http://schemas.openxmlformats.org/markup-compatibility/2006"xmlns:local&#61;"clr-namespace:Target"mc:Ignorable&#61;"d"Title&#61;"MainWindow" Height&#61;"350" Width&#61;"525"><Window.Resources><Style TargetType&#61;"{x:Type TreeViewItem}">"Foreground" Value&#61;"Blue"/>"FontSize" Value&#61;"12"/>Style><Style TargetType&#61;"{x:Type TextBox}">"Width" Value&#61;"80"/>"TextWrapping" Value&#61;"Wrap"/>Style><XmlDataProvider x:Key&#61;"MyEmployeeData" XPath&#61;"/EmployeeData"><x:XData><EmployeeData xmlns&#61;""><EmployeeInfo><EmployeeInfoData>Employee1EmployeeInfoData><Item Type&#61;"FirstName">JesperItem><Item Type&#61;"LastName">AabergItem><Item Type&#61;"EmployeeNumber">12345Item>EmployeeInfo><EmployeeInfo><EmployeeInfoData>Employee2EmployeeInfoData><Item Type&#61;"FirstName">DominikItem><Item Type&#61;"LastName">PaihaItem><Item Type&#61;"EmployeeNumber">98765Item>EmployeeInfo>EmployeeData>x:XData>XmlDataProvider><TextBlock Text&#61;"{Binding XPath&#61;EmployeeInfoData}" />HierarchicalDataTemplate>Window.Resources><StackPanel><TextBlock>TreeView control with TreeViewItem content explicitly defined as Header stringsTextBlock><TreeView><TreeViewItem Header&#61;"Employee1"><TreeViewItem Header&#61;"Jesper"/><TreeViewItem Header&#61;"Aaberg"/><TreeViewItem Header&#61;"12345"/>TreeViewItem><TreeViewItem Header&#61;"Employee2"><TreeViewItem Header&#61;"Dominik"/><TreeViewItem Header&#61;"Paiha"/><TreeViewItem Header&#61;"98765"/>TreeViewItem>TreeView><TextBlock>TreeView control with leaf nodes specified asItems that are ButtonsTextBlock><TreeView><TreeViewItem.Items><Button Click&#61;"OnClick">JesperButton><Button Click&#61;"OnClick">AabergButton><Button Click&#61;"OnClick">12345Button>TreeViewItem.Items>TreeViewItem><TreeViewItem Header&#61;"Employee2"><TreeViewItem.Items><Button Click&#61;"OnClick">DominikButton><Button Click&#61;"OnClick">PaihaButton><Button Click&#61;"OnClick">98765Button>TreeViewItem.Items>TreeViewItem>TreeView><TextBlock>TreeView control with root nodesdefined as Buttons and and leaf nodesthat are Header stringsTextBlock><TreeView><TreeViewItem><TreeViewItem.Header><Button Click&#61;"OnClick">Employee1Button>TreeViewItem.Header><TreeViewItem Header&#61;"Jesper"/><TreeViewItem Header&#61;"Aaberg"/><TreeViewItem Header&#61;"12345"/>TreeViewItem><TreeViewItem><TreeViewItem.Header><Button Click&#61;"OnClick">Employee2Button>TreeViewItem.Header><TreeViewItem Header&#61;"Dominik"/><TreeViewItem Header&#61;"Paiha"/><TreeViewItem Header&#61;"98765"/>TreeViewItem>TreeView><TextBlock>TreeView control createdby databinding with an XMLDataProvider and using a HierarchicalDataTemplateTextBlock><TreeView ItemsSource&#61;"{Binding Source&#61;{StaticResource MyEmployeeData}, XPath&#61;EmployeeInfo}"/><TextBlock>TreeView control whose Items contain DockPanel controlswith embedded Image and TextBlock contentTextBlock><TreeView><TreeViewItem Header&#61;"Animals"><TreeViewItem.Items><DockPanel><Image Source&#61;"data\fish.png"/><TextBlock Margin&#61;"5" Foreground&#61;"Brown"FontSize&#61;"12">FishTextBlock>DockPanel><DockPanel><Image Source&#61;"data\dog.png"/><TextBlock Margin&#61;"5" Foreground&#61;"Brown"FontSize&#61;"12">DogTextBlock>DockPanel><DockPanel><Image Source&#61;"data\cat.png"/><TextBlock Margin&#61;"5" Foreground&#61;"Brown"FontSize&#61;"12">CatTextBlock>DockPanel>TreeViewItem.Items>TreeViewItem>TreeView>StackPanel>
Window>

后台代码

using System.Windows;
using System.Windows.Controls;namespace Target
{///

/// Interaction logic for MainWindow.xaml/// public partial class MainWindow : Window{public MainWindow(){InitializeComponent();}private void OnClick(object sender, RoutedEventArgs e){var targetButton &#61; sender as Button;MessageBox.Show(targetButton?.Content &#43; " invoked.");}}
}

推荐阅读
author-avatar
梁lxc_131
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有