<Windowx: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><StyleTargetType&#61;"{x:Type TreeViewItem}">"Foreground" Value&#61;"Blue"/>"FontSize" Value&#61;"12"/>Style><StyleTargetType&#61;"{x:Type TextBox}">"Width" Value&#61;"80"/>"TextWrapping" Value&#61;"Wrap"/>Style><XmlDataProviderx:Key&#61;"MyEmployeeData"XPath&#61;"/EmployeeData"><x:XData><EmployeeDataxmlns&#61;""><EmployeeInfo><EmployeeInfoData>Employee1EmployeeInfoData><ItemType&#61;"FirstName">JesperItem><ItemType&#61;"LastName">AabergItem><ItemType&#61;"EmployeeNumber">12345Item>EmployeeInfo><EmployeeInfo><EmployeeInfoData>Employee2EmployeeInfoData><ItemType&#61;"FirstName">DominikItem><ItemType&#61;"LastName">PaihaItem><ItemType&#61;"EmployeeNumber">98765Item>EmployeeInfo>EmployeeData>x:XData>XmlDataProvider><TextBlockText&#61;"{Binding XPath&#61;EmployeeInfoData}"/>HierarchicalDataTemplate>Window.Resources><StackPanel><TextBlock>TreeView control with TreeViewItem content explicitly defined as Header stringsTextBlock><TreeView><TreeViewItemHeader&#61;"Employee1"><TreeViewItemHeader&#61;"Jesper"/><TreeViewItemHeader&#61;"Aaberg"/><TreeViewItemHeader&#61;"12345"/>TreeViewItem><TreeViewItemHeader&#61;"Employee2"><TreeViewItemHeader&#61;"Dominik"/><TreeViewItemHeader&#61;"Paiha"/><TreeViewItemHeader&#61;"98765"/>TreeViewItem>TreeView><TextBlock>TreeView control with leaf nodes specified asItems that are ButtonsTextBlock><TreeView><TreeViewItem.Items><ButtonClick&#61;"OnClick">JesperButton><ButtonClick&#61;"OnClick">AabergButton><ButtonClick&#61;"OnClick">12345Button>TreeViewItem.Items>TreeViewItem><TreeViewItemHeader&#61;"Employee2"><TreeViewItem.Items><ButtonClick&#61;"OnClick">DominikButton><ButtonClick&#61;"OnClick">PaihaButton><ButtonClick&#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><ButtonClick&#61;"OnClick">Employee1Button>TreeViewItem.Header><TreeViewItemHeader&#61;"Jesper"/><TreeViewItemHeader&#61;"Aaberg"/><TreeViewItemHeader&#61;"12345"/>TreeViewItem><TreeViewItem><TreeViewItem.Header><ButtonClick&#61;"OnClick">Employee2Button>TreeViewItem.Header><TreeViewItemHeader&#61;"Dominik"/><TreeViewItemHeader&#61;"Paiha"/><TreeViewItemHeader&#61;"98765"/>TreeViewItem>TreeView><TextBlock>TreeView control createdby databinding with an XMLDataProvider and using a HierarchicalDataTemplateTextBlock><TreeViewItemsSource&#61;"{Binding Source&#61;{StaticResource MyEmployeeData}, XPath&#61;EmployeeInfo}"/><TextBlock>TreeView control whose Items contain DockPanel controlswith embedded Image and TextBlock contentTextBlock><TreeView><TreeViewItemHeader&#61;"Animals"><TreeViewItem.Items><DockPanel><ImageSource&#61;"data\fish.png"/><TextBlockMargin&#61;"5"Foreground&#61;"Brown"FontSize&#61;"12">FishTextBlock>DockPanel><DockPanel><ImageSource&#61;"data\dog.png"/><TextBlockMargin&#61;"5"Foreground&#61;"Brown"FontSize&#61;"12">DogTextBlock>DockPanel><DockPanel><ImageSource&#61;"data\cat.png"/><TextBlockMargin&#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/// publicpartialclassMainWindow:Window{publicMainWindow(){InitializeComponent();}privatevoidOnClick(object sender,RoutedEventArgs e){var targetButton &#61; sender as Button;MessageBox.Show(targetButton?.Content &#43;" invoked.");}} }
Irish budget airline Ryanair announced plans to significantly increase its route network from Frankfurt Airport, marking a direct challenge to Lufthansa, Germany's leading carrier. ...
[详细]