BehaviorTreeView.xaml 2.9 KB

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