MainWindow.xaml 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <Window x:Class="WpfSample.MainWindow"
  2. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  3. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  6. xmlns:local="clr-namespace:WpfSample"
  7. xmlns:vm="clr-namespace:WpfSample.ViewModels"
  8. mc:Ignorable="d"
  9. Title="MainWindow" Height="450" Width="800"
  10. BorderThickness="0" Background="Coral">
  11. <Grid>
  12. <Grid.RowDefinitions>
  13. <RowDefinition Height="36"/>
  14. <RowDefinition Height="*"/>
  15. </Grid.RowDefinitions>
  16. <StackPanel Grid.Row="0" Orientation="Horizontal">
  17. <Button Command="{Binding AddItemCommand}" Content="Add"/>
  18. <TextBlock x:Name="tb1" local:PropADemo.Text="Hello World"/>
  19. <TextBlock x:Name="tb2" local:PropADemo.Text="Greeting"/>
  20. </StackPanel>
  21. <TreeView Grid.Row="1" ItemsSource="{Binding Groups}">
  22. <TreeView.Resources>
  23. <HierarchicalDataTemplate DataType="{x:Type vm:DemoGroupViewModel}" ItemsSource="{Binding Items}">
  24. <Border Background="Coral">
  25. <TextBlock Text="{Binding Message}"/>
  26. </Border>
  27. </HierarchicalDataTemplate>
  28. <HierarchicalDataTemplate DataType="{x:Type vm:DemoItemViewModel}">
  29. <Border Background="#669999">
  30. <TextBlock Text="{Binding Message}"/>
  31. </Border>
  32. </HierarchicalDataTemplate>
  33. </TreeView.Resources>
  34. <TreeView.ItemContainerStyle>
  35. <Style TargetType="TreeViewItem">
  36. <Setter Property="AllowDrop" Value="True"/>
  37. <EventSetter Event="MouseMove" Handler="TreeViewItem_MouseMove"/>
  38. <EventSetter Event="DragEnter" Handler="TreeViewItem_DragEnter"/>
  39. <EventSetter Event="DragOver" Handler="TreeViewItem_DragOver"/>
  40. <EventSetter Event="DragLeave" Handler="TreeViewItem_DragLeave"/>
  41. <EventSetter Event="Drop" Handler="TreeViewItem_Drop"/>
  42. </Style>
  43. </TreeView.ItemContainerStyle>
  44. </TreeView>
  45. </Grid>
  46. </Window>