BehaviorTreeView.xaml 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. </UserControl.Resources>
  19. <UserControl.CommandBindings>
  20. <CommandBinding Command="ApplicationCommands.New" Executed="MenuNewNode_Executed" />
  21. <CommandBinding Command="ApplicationCommands.Delete" Executed="MenuDeleteNode_Executed" />
  22. </UserControl.CommandBindings>
  23. <UserControl.ContextMenu>
  24. <ContextMenu>
  25. <MenuItem Header="New Node" Command="ApplicationCommands.New"
  26. CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
  27. <MenuItem Header="Delete Node" Command="ApplicationCommands.Delete"
  28. CommandTarget="{Binding Path=PlacementTarget, RelativeSource={RelativeSource AncestorType=ContextMenu}}" />
  29. </ContextMenu>
  30. </UserControl.ContextMenu>
  31. <Grid>
  32. <ListBox Name="listBox" SelectionMode="Extended" ItemsSource="{Binding TreeNodes}" >
  33. <ListBox.Resources>
  34. <Style TargetType="{x:Type ListBoxItem}">
  35. <Setter Property="Canvas.Left" Value="{Binding X}"/>
  36. <Setter Property="Canvas.Top" Value="{Binding Y}"/>
  37. </Style>
  38. </ListBox.Resources>
  39. <ListBox.ItemsPanel>
  40. <ItemsPanelTemplate>
  41. <Canvas AllowDrop="True" />
  42. </ItemsPanelTemplate>
  43. </ListBox.ItemsPanel>
  44. <ListBox.ItemTemplate>
  45. <DataTemplate>
  46. <Canvas MouseDown="ListBoxItem_MouseDown" MouseUp="ListBoxItem_MouseUp" MouseMove="ListBoxItem_MouseMove">
  47. <Rectangle Width="{Binding Width}" Height="{Binding Height}" Cursor="Hand" StrokeThickness="1.3" RadiusX="4" RadiusY="4"
  48. Stroke="{StaticResource treeNodeBorderBrush}" Fill="{StaticResource treeNodeFillBrush}" />
  49. <Line X1="{Binding ConnectorX1}" Y1="{Binding ConnectorY1}" X2="{Binding ConnectorX2}" Y2="{Binding ConnectorY2}"
  50. Stroke="Black" StrokeThickness="2" ></Line>
  51. </Canvas>
  52. </DataTemplate>
  53. </ListBox.ItemTemplate>
  54. </ListBox>
  55. </Grid>
  56. </UserControl>