BehaviorTreeView.xaml 3.1 KB

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