BehaviorTreeView.xaml 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  2. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  3. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  4. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  5. x:Class="BehaviorTree.BehaviorTreeView"
  6. mc:Ignorable="d" d:DesignHeight="600" d:DesignWidth="800">
  7. <UserControl.Resources>
  8. <LinearGradientBrush x:Key="treeNodeFillBrush" StartPoint="0,0" EndPoint="0,1">
  9. <GradientStop Color="White" Offset="0" />
  10. <GradientStop Color="#7FC9FF" Offset="0.6" />
  11. </LinearGradientBrush>
  12. <SolidColorBrush x:Key="treeNodeBorderBrush" Color="Black" />
  13. </UserControl.Resources>
  14. <UserControl.CommandBindings>
  15. <CommandBinding Command="ApplicationCommands.New" Executed="MenuNewNode_Executed" />
  16. <CommandBinding Command="ApplicationCommands.Delete" Executed="MenuDeleteNode_Executed" />
  17. </UserControl.CommandBindings>
  18. <UserControl.ContextMenu>
  19. <ContextMenu>
  20. <MenuItem Header="New" Command="ApplicationCommands.New"
  21. CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
  22. <MenuItem Header="Delete" Command="ApplicationCommands.Delete"
  23. CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
  24. </ContextMenu>
  25. </UserControl.ContextMenu>
  26. <Grid>
  27. <ListBox Name="listBox" SelectionMode="Extended" ItemsSource="{Binding TreeNodes}" x:FieldModifier="private">
  28. <ListBox.Resources>
  29. <Style TargetType="{x:Type ListBoxItem}">
  30. <Setter Property="Canvas.Left" Value="{Binding X}" />
  31. <Setter Property="Canvas.Top" Value="{Binding Y}" />
  32. </Style>
  33. </ListBox.Resources>
  34. <ListBox.ItemsPanel>
  35. <ItemsPanelTemplate>
  36. <Canvas AllowDrop="True" />
  37. </ItemsPanelTemplate>
  38. </ListBox.ItemsPanel>
  39. <ListBox.ItemTemplate>
  40. <DataTemplate>
  41. <Canvas MouseDown="ListBoxItem_MouseDown" MouseUp="ListBoxItem_MouseUp" MouseMove="ListBoxItem_MouseMove">
  42. <Rectangle Name="rectNode" Width="{Binding Width}" Height="{Binding Height}" Cursor="Hand" StrokeThickness="4"
  43. RadiusX="4" RadiusY="4" Stroke="{StaticResource treeNodeBorderBrush}" Fill="{StaticResource treeNodeFillBrush}"/>
  44. <Line X1="{Binding ConnectorX1}" Y1="{Binding ConnectorY1}" X2="{Binding ConnectorX2}" Y2="{Binding ConnectorY2}"
  45. Stroke="Black" StrokeThickness="2" />
  46. <StackPanel>
  47. <StackPanel Orientation="Horizontal">
  48. <Label Content="{Binding Num}"></Label>
  49. <Label Content="{Binding X}"></Label>
  50. <Label Content="{Binding Y}"></Label>
  51. </StackPanel>
  52. <StackPanel Orientation="Horizontal">
  53. <Label Content="{Binding Prelim}"></Label>
  54. <Label Content="{Binding Modify}"></Label>
  55. </StackPanel>
  56. </StackPanel>
  57. </Canvas>
  58. <DataTemplate.Triggers>
  59. <DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
  60. <Setter TargetName="rectNode" Property="Stroke" Value="Green" />
  61. </DataTrigger>
  62. </DataTemplate.Triggers>
  63. </DataTemplate>
  64. </ListBox.ItemTemplate>
  65. </ListBox>
  66. </Grid>
  67. </UserControl>