办理Nodify框架因自带放大缩小、平移功能导致拖拽添加的控件无法正确在鼠标 ...

万万哇  金牌会员 | 2024-9-24 17:21:43 | 来自手机 | 显示全部楼层 | 阅读模式
打印 上一主题 下一主题

主题 856|帖子 856|积分 2568

ViewModel中写具体关键的几段代码:
  1. var editor = sender as NodifyEditor;              
  2.      Point p = e.GetPosition(editor);
  3.      //放大缩小比例
  4.      double scale = editor.ViewportZoom;
  5.      //经过放大缩小、平移后获得坐标点位置
  6.      p = new Point(Math.Round((p.X - editor.ViewportTransform.Value.OffsetX) / scale,0), Math.Round((p.Y - editor.ViewportTransform.Value.OffsetY) / scale,0));
复制代码
详细代码如下
CustomInterfaceView.xaml
  1. <UserControl x:Class="Ueyes.Intergration.AgingEditor.View.CustomInterfaceView"
  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:local="clr-namespace:Ueyes.Intergration.AgingEditor"
  7.              xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
  8.              xmlns:nodify="https://miroiu.github.io/nodify"
  9.              xmlns:shared="clr-namespace:Ueyes.Intergration.AgingEditor.Share;assembly=Ueyes.Intergration.AgingEditor.Share"
  10.              xmlns:h="http://schemas.microsoft.com/xaml/behaviors"
  11.              mc:Ignorable="d" Name="custom"
  12.              d:DesignHeight="800" d:DesignWidth="1000">
  13.     <UserControl.Resources>
  14.         <shared:TargetTypeToVisibilityConverter x:Key="TargetTypeToVisibilityConverter"/>
  15.         <shared:BindingProxy x:Key="EditorProxy" DataContext="{Binding}" />
  16.         <shared:BindingProxy x:Key="BlackboardProxy" DataContext="{Binding SelectedState.Action}" />
  17.         <DataTemplate x:Key="ToolBoxStyle">
  18.             <Grid Margin="2" Background="Transparent">
  19.                 <Grid.ColumnDefinitions>
  20.                     <ColumnDefinition Width="30"/>
  21.                     <ColumnDefinition/>
  22.                 </Grid.ColumnDefinitions>
  23.                 <iconPacks:PackIconMaterial x:Name="icon" Kind="Ellipse" BorderThickness="1" VerticalAlignment="Stretch" Width="24" HorizontalAlignment="Stretch"/>
  24.                 <TextBlock x:Name="txt" Grid.Column="1" Text="{Binding TypeName}" Margin="4"/>
  25.             </Grid>
  26.             <DataTemplate.Triggers>
  27.                 <DataTrigger Binding="{Binding TypeName}" Value="Button">
  28.                     <Setter Property="Kind" TargetName="icon" Value="GestureTapButton"/>
  29.                     <Setter Property="Text" TargetName="txt" Value="{Binding Header}"/>
  30.                 </DataTrigger>
  31.                 <DataTrigger Binding="{Binding TypeName}" Value="TextBox">
  32.                     <Setter Property="Kind" TargetName="icon" Value="Numeric8Box"/>
  33.                     <Setter Property="Text" TargetName="txt" Value="{Binding Header}"/>
  34.                 </DataTrigger>
  35.                 <DataTrigger Binding="{Binding TypeName}" Value="TextBlock">
  36.                     <Setter Property="Kind" TargetName="icon" Value="FormatText"/>
  37.                     <Setter Property="Text" TargetName="txt" Value="{Binding Header}"/>
  38.                 </DataTrigger>      
  39.             </DataTemplate.Triggers>
  40.         </DataTemplate>
  41.         <DataTemplate x:Key="ButtonTemplate">
  42.             <Button Command="{Binding DataContext.ClickCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" CommandParameter="{Binding .}">
  43.                 <Button.Content>
  44.                     <shared:EditableTextBlock IsEditable="{Binding IsEditable}"
  45.                                     IsEditing="{Binding IsRenaming}" Text="{Binding Name}" />
  46.                 </Button.Content>
  47.             </Button>
  48.         </DataTemplate>
  49.         <DataTemplate x:Key="TextBlockTemplate">
  50.             <shared:EditableTextBlock IsEditable="{Binding IsEditable}" Foreground="Black" MaxLength="30"
  51.                  IsEditing="{Binding IsRenaming}" Text="{Binding Name}" />
  52.         </DataTemplate>
  53.         <DataTemplate x:Key="TextBoxTemplate">
  54.             <TextBox Text="{Binding Name}" IsEnabled="{Binding IsEditable}" MinHeight="25" MaxLength="30"/>
  55.         </DataTemplate>
  56.     </UserControl.Resources>
  57.     <Grid>
  58.         <Grid.ColumnDefinitions>
  59.             <ColumnDefinition Width="Auto" />
  60.             <ColumnDefinition />
  61.             <ColumnDefinition Width="Auto"/>
  62.             <ColumnDefinition Width="Auto"/>
  63.         </Grid.ColumnDefinitions>
  64.         <nodify:NodifyEditor x:Name="Editor"  Grid.Column="1" Background="White"
  65.                              ItemsSource="{Binding States}" AllowDrop="True"
  66.                              SelectedItem="{Binding SelectedState}" DisableZooming="False" DisablePanning="False"
  67.                              SelectedItems="{Binding SelectedStates}">
  68.             <h:Interaction.Triggers>
  69.                 <h:EventTrigger EventName="Drop">
  70.                     <h:CallMethodAction TargetObject="{Binding}"
  71.                                         MethodName="nodify_Drop"/>
  72.                   
  73.                 </h:EventTrigger>
  74.             </h:Interaction.Triggers>
  75.             
  76.             <nodify:NodifyEditor.ItemTemplate>
  77.                 <DataTemplate DataType="{x:Type local:StateViewModel}">
  78.                     <nodify:StateNode Anchor="{Binding Anchor, Mode=OneWayToSource}" Padding="10 12"
  79.                                     Content="{Binding}" IsConnected="False" ToolTip="{Binding Location}">
  80.                         <nodify:StateNode.ContentTemplate>
  81.                             <DataTemplate DataType="{x:Type local:StateViewModel}">
  82.                                 <ContentControl Content="{Binding}" >
  83.                                     <ContentControl.Style>
  84.                                         <Style TargetType="{x:Type ContentControl}">
  85.                                             <Style.Triggers>
  86.                                                 <DataTrigger Binding="{Binding TargetType}" Value="Button">
  87.                                                     <Setter Property="ContentTemplate" Value="{StaticResource ButtonTemplate}" />
  88.                                                 </DataTrigger>
  89.                                                 <DataTrigger Binding="{Binding TargetType}" Value="TextBlock">
  90.                                                     <Setter Property="ContentTemplate" Value="{StaticResource TextBlockTemplate}" />
  91.                                                 </DataTrigger>
  92.                                                 <DataTrigger Binding="{Binding TargetType}" Value="TextBox">
  93.                                                     <Setter Property="ContentTemplate" Value="{StaticResource TextBoxTemplate}" />
  94.                                                 </DataTrigger>
  95.                                             </Style.Triggers>
  96.                                         </Style>
  97.                                     </ContentControl.Style>
  98.                                 </ContentControl>
  99.                             </DataTemplate>
  100.                         </nodify:StateNode.ContentTemplate>
  101.                         <nodify:StateNode.Style>
  102.                             <Style BasedOn="{StaticResource {x:Type nodify:StateNode}}" TargetType="{x:Type nodify:StateNode}">
  103.                                 <Setter Property="BorderThickness" Value="0"/>
  104.                                 <Style.Triggers>
  105.                                     <DataTrigger Binding="{Binding TargetType}" Value="Button">
  106.                                         <Setter Property="Background" Value="White" />
  107.                                     </DataTrigger>
  108.                                     <DataTrigger Binding="{Binding TargetType}" Value="TextBlock">
  109.                                         <Setter Property="Foreground" Value="Black"/>
  110.                                         <Setter Property="Background" Value="White" />
  111.                                     </DataTrigger>
  112.                                     <DataTrigger Binding="{Binding TargetType}" Value="TextBox">
  113.                                         <Setter Property="Background" Value="White" />
  114.                                     </DataTrigger>
  115.                                 </Style.Triggers>
  116.                             </Style>
  117.                         </nodify:StateNode.Style>
  118.                     </nodify:StateNode>
  119.                 </DataTemplate>
  120.             </nodify:NodifyEditor.ItemTemplate>
  121.             <nodify:NodifyEditor.ItemContainerStyle>
  122.                 <Style BasedOn="{StaticResource {x:Type nodify:ItemContainer}}" TargetType="{x:Type nodify:ItemContainer}">
  123.                     <Setter Property="BorderBrush" Value="Transparent" />
  124.                     <Setter Property="Location" Value="{Binding Location}" />
  125.                     <Setter Property="ActualSize" Value="{Binding Size, Mode=OneWayToSource}" />
  126.                     <Setter Property="ContextMenu">
  127.                         <Setter.Value>
  128.                             <ContextMenu DataContext="{Binding DataContext, Source={StaticResource EditorProxy}}">
  129.                                 <MenuItem
  130.                                     Command="{Binding DeleteCommand}"
  131.                                     Header="_Delete"
  132.                                     Icon="{StaticResource DeleteIcon}"
  133.                                     InputGestureText="Delete"/>
  134.                                 <MenuItem
  135.                                     Command="{Binding CopyCommand}"
  136.                                     Header="_Copy"
  137.                                     Icon="{StaticResource CopyIcon}"
  138.                                     InputGestureText="Ctrl+D" />
  139.                                 <MenuItem
  140.                                     Command="{Binding RenameCommand}"
  141.                                     Header="_Rename"
  142.                                     Icon="{StaticResource RenameIcon}" />
  143.                                 <MenuItem
  144.                                     Command="{Binding EditableCommand}"
  145.                                     Header="_IsEditable"
  146.                                     Icon="{StaticResource EditIcon}" />
  147.                                 <!--<MenuItem
  148.                                     Command="{Binding MoveCommand}"
  149.                                     Header="_IsMove"
  150.                                     Icon="{StaticResource EditIcon}" />-->
  151.                                 <MenuItem Header="_Alignment" Icon="{StaticResource AlignTopIcon}">
  152.                                     <MenuItem
  153.                                         Command="{x:Static nodify:EditorCommands.Align}"
  154.                                         CommandParameter="Top"
  155.                                         Header="_Top"
  156.                                         Icon="{StaticResource AlignTopIcon}" />
  157.                                     <MenuItem
  158.                                         Command="{x:Static nodify:EditorCommands.Align}"
  159.                                         CommandParameter="Left"
  160.                                         Header="_Left"
  161.                                         Icon="{StaticResource AlignLeftIcon}" />
  162.                                     <MenuItem
  163.                                         Command="{x:Static nodify:EditorCommands.Align}"
  164.                                         CommandParameter="Bottom"
  165.                                         Header="_Bottom"
  166.                                         Icon="{StaticResource AlignBottomIcon}" />
  167.                                     <MenuItem
  168.                                         Command="{x:Static nodify:EditorCommands.Align}"
  169.                                         CommandParameter="Right"
  170.                                         Header="_Right"
  171.                                         Icon="{StaticResource AlignRightIcon}" />
  172.                                     <MenuItem
  173.                                         Command="{x:Static nodify:EditorCommands.Align}"
  174.                                         CommandParameter="Middle"
  175.                                         Header="_Middle"
  176.                                         Icon="{StaticResource AlignMiddleIcon}" />
  177.                                     <MenuItem
  178.                                         Command="{x:Static nodify:EditorCommands.Align}"
  179.                                         CommandParameter="Center"
  180.                                         Header="_Center"
  181.                                         Icon="{StaticResource AlignCenterIcon}" />
  182.                                 </MenuItem>
  183.                             </ContextMenu>
  184.                         </Setter.Value>
  185.                     </Setter>
  186.                 </Style>
  187.             </nodify:NodifyEditor.ItemContainerStyle>
  188.             <nodify:NodifyEditor.ContextMenu>
  189.                 <ContextMenu DataContext="{Binding DataContext, Source={StaticResource EditorProxy}}">
  190.                     <MenuItem
  191.                         Command="{Binding AddButtonCommand}"
  192.                         CommandParameter="{Binding PlacementTarget.MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
  193.                         Header="_Add Button"
  194.                         Icon="{StaticResource AddStateIcon}"/>
  195.                     <MenuItem
  196.                         Command="{Binding AddTextBlockCommand}"
  197.                         CommandParameter="{Binding PlacementTarget.MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
  198.                         Header="_Add TextBlock"
  199.                         Icon="{StaticResource AddStateIcon}"/>
  200.                     <MenuItem
  201.                         Command="{Binding AddTextBoxCommand}"
  202.                         CommandParameter="{Binding PlacementTarget.MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
  203.                         Header="_Add TextBox"
  204.                         Icon="{StaticResource AddStateIcon}"/>
  205.                     <MenuItem
  206.                         Command="{Binding DeleteCommand}"
  207.                         Header="_Delete"
  208.                         Icon="{StaticResource DeleteIcon}"
  209.                         InputGestureText="Delete" />
  210.                     <Separator Background="{DynamicResource BorderBrush}" />
  211.                     <MenuItem
  212.                         Command="{x:Static nodify:EditorCommands.SelectAll}"
  213.                         Header="_Select All"
  214.                         Icon="{StaticResource SelectAllIcon}"
  215.                         InputGestureText="Ctrl+A" />
  216.                 </ContextMenu>
  217.             </nodify:NodifyEditor.ContextMenu>
  218.             <!--快捷键添加删除新模块操作-->
  219.             <nodify:NodifyEditor.InputBindings>
  220.                 <KeyBinding Key="Delete" Command="{Binding DeleteCommand}" />
  221.                 <!--<KeyBinding
  222.                         Key="A"
  223.                         Command="{Binding AddStateCommand}"
  224.                         CommandParameter="{Binding MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type nodify:NodifyEditor}}}"
  225.                         Modifiers="Shift" />-->
  226.                 <KeyBinding Command="{Binding CopyCommand}"
  227.                          Key="D" Modifiers="Ctrl"/>
  228.                 <KeyBinding Command="{x:Static nodify:EditorCommands.SelectAll}"
  229.                          Key="A" Modifiers="Ctrl"/>
  230.             </nodify:NodifyEditor.InputBindings>
  231.         </nodify:NodifyEditor>
  232.         <Expander
  233.                Padding="0,1,4,3"
  234.                HorizontalAlignment="Left"
  235.                HorizontalContentAlignment="Left"
  236.                VerticalContentAlignment="Center"
  237.                Background="{DynamicResource PanelBackgroundBrush}"
  238.                ExpandDirection="Left"
  239.                IsExpanded="True"
  240.                Visibility="Visible">
  241.             <Expander.Style>
  242.                 <Style BasedOn="{StaticResource {x:Type Expander}}" TargetType="{x:Type Expander}">
  243.                     <Setter Property="Tag" Value="{StaticResource ExpandRightIcon}" />
  244.                     <Style.Triggers>
  245.                         <Trigger Property="IsExpanded" Value="True">
  246.                             <Setter Property="Tag" Value="{StaticResource ExpandLeftIcon}" />
  247.                         </Trigger>
  248.                     </Style.Triggers>
  249.                 </Style>
  250.             </Expander.Style>
  251.             <Border
  252.                  Width="450"
  253.                  Padding="10"
  254.                  HorizontalAlignment="Stretch"
  255.                  BorderBrush="{DynamicResource BackgroundBrush}"
  256.                  BorderThickness="1">
  257.                 <Grid>
  258.                     <Grid.RowDefinitions>
  259.                         <RowDefinition Height="3*"/>
  260.                         <RowDefinition Height="6*" />
  261.                         <RowDefinition Height="1*" />
  262.                     </Grid.RowDefinitions>
  263.                     <!--  TRANSITIONS  -->
  264.                     <Grid
  265.                  Grid.Row="0"
  266.                  Margin="0,10,0,10"                        
  267.                  Visibility="{Binding SelectedState, Converter={shared:BooleanToVisibilityConverter Negate=True}}">
  268.                         <Grid VerticalAlignment="Top">
  269.                             <ListBox x:Name="CtlList" ItemsSource="{Binding ThumbList}" Background="Transparent"
  270.                                      ItemTemplate="{StaticResource ToolBoxStyle}" SelectedItem="{Binding ThumbSelectedItem}" BorderThickness="0">
  271.                                 <h:Interaction.Triggers>
  272.                                     <h:EventTrigger EventName="PreviewMouseMove">
  273.                                         <h:CallMethodAction MethodName="CtlList_PreviewMouseMove"
  274.                                                             TargetObject="{Binding ElementName=custom,Path=DataContext}"/>
  275.                                     </h:EventTrigger>
  276.                                 </h:Interaction.Triggers>
  277.                             </ListBox>
  278.                             <!--<ItemsControl ItemsSource="{Binding ThumbList}">
  279.                                 <ItemsControl.ItemTemplate>
  280.                                     <DataTemplate>
  281.                                         <Border Margin="5,3" Tag="{Binding TypeName}">
  282.                                             <StackPanel Orientation="Horizontal">
  283.                                                 <iconPacks:PackIconMaterial x:Name="icon" Kind="GestureTapButton" BorderThickness="1"
  284.                                                                             Width="30" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
  285.                                                 <TextBlock x:Name="txt" Grid.Column="1" Text="{Binding Header}" Margin="4"/>
  286.                                             </StackPanel>
  287.                                             <h:Interaction.Triggers>
  288.                                                 <h:EventTrigger EventName="MouseLeftButtonDown">
  289.                                                     <h:CallMethodAction MethodName="Border_MouseLeftButtonDown"
  290.                                                                         TargetObject="{Binding ElementName=custom,Path=DataContext}"/>
  291.                                                 </h:EventTrigger>
  292.                                             </h:Interaction.Triggers>
  293.                                         </Border>
  294.                                     </DataTemplate>
  295.                                 </ItemsControl.ItemTemplate>
  296.                             </ItemsControl>-->
  297.                         </Grid>
  298.                     </Grid>
  299.                     <!--  STATES  -->
  300.                     <Grid Grid.Row="0" Grid.RowSpan="2" Margin="0,10,0,10" Visibility="{Binding SelectedState, Converter={shared:BooleanToVisibilityConverter}}">
  301.                         <Grid.RowDefinitions>
  302.                             <RowDefinition Height="Auto" />
  303.                             <RowDefinition Height="Auto" />
  304.                             <RowDefinition />
  305.                         </Grid.RowDefinitions>
  306.                         <!--  STATE NAME  -->
  307.                         <Grid>
  308.                             <Grid.ColumnDefinitions>
  309.                                 <ColumnDefinition Width="*" />
  310.                                 <ColumnDefinition Width="Auto" />
  311.                             </Grid.ColumnDefinitions>
  312.                             <shared:EditableTextBlock
  313.                                      FontSize="16"
  314.                                      FontWeight="Bold"
  315.                                      Foreground="{DynamicResource ForegroundBrush}"
  316.                                      IsEditable="{Binding SelectedState.IsEditable}"
  317.                                      IsEditing="{Binding IsChecked, ElementName=EditStateName}"
  318.                                      MaxLength="20"
  319.                                      Text="{Binding SelectedState.Name}" />
  320.                             <CheckBox
  321.                                     x:Name="EditStateName"
  322.                                     Grid.Column="1"
  323.                                     Content="{StaticResource EditIcon}"
  324.                                     Style="{StaticResource IconCheckBox}"
  325.                                     Visibility="{Binding SelectedState.IsEditable, Converter={shared:BooleanToVisibilityConverter}}" />
  326.                         </Grid>
  327.                         <Separator
  328.                               Grid.Row="1"
  329.                               Width="Auto"
  330.                               Height="2"
  331.                               Margin="0,2,0,10"/>
  332.                         <ScrollViewer
  333.                               Grid.Row="2"
  334.                               VerticalScrollBarVisibility="Auto"
  335.                               Visibility="{Binding SelectedState.Action, Converter={shared:BooleanToVisibilityConverter}}">
  336.                             <Grid IsSharedSizeScope="True">
  337.                                 <Grid.ColumnDefinitions>
  338.                                     <ColumnDefinition Width="Auto" />
  339.                                     <ColumnDefinition />
  340.                                 </Grid.ColumnDefinitions>
  341.                                 <Grid.RowDefinitions>
  342.                                     <RowDefinition Height="Auto" />
  343.                                     <RowDefinition Height="Auto" />
  344.                                     <RowDefinition Height="Auto" />
  345.                                     <RowDefinition />
  346.                                 </Grid.RowDefinitions>
  347.                                 <!--  ACTION  -->
  348.                                 <TextBlock
  349.                                      Margin="0,0,10,0"
  350.                                      VerticalAlignment="Center"
  351.                                      Text="操作" />
  352.                                 <ComboBox
  353.                                      Grid.Column="1"
  354.                                      DisplayMemberPath="Name"
  355.                                      IsEnabled="{Binding SelectedState.IsEditable}"
  356.                                      ItemsSource="{Binding Blackboard.Actions}"
  357.                                      SelectedItem="{Binding SelectedState.ActionReference}"
  358.                                      />
  359.                                 <!--  INPUT  -->
  360.                                 <Expander
  361.                                      Grid.Row="1"
  362.                                      Grid.ColumnSpan="2"
  363.                                      Margin="0,5,0,0"
  364.                                      Padding="0,5,0,0"
  365.                                      BorderBrush="{DynamicResource BackgroundBrush}"
  366.                                      BorderThickness="0,0,0,1"
  367.                                      FontWeight="Bold"
  368.                                      Header="Input"
  369.                                      IsExpanded="True"
  370.                                      Visibility="{Binding SelectedState.Action.Input.Count, Converter={shared:BooleanToVisibilityConverter}}">
  371.                                     <Expander.Style>
  372.                                         <Style BasedOn="{StaticResource {x:Type Expander}}" TargetType="{x:Type Expander}">
  373.                                             <Setter Property="Tag" Value="{StaticResource ExpandRightIcon}" />
  374.                                             <Style.Triggers>
  375.                                                 <Trigger Property="IsExpanded" Value="True">
  376.                                                     <Setter Property="Tag" Value="{StaticResource ExpandDownIcon}" />
  377.                                                 </Trigger>
  378.                                             </Style.Triggers>
  379.                                         </Style>
  380.                                     </Expander.Style>
  381.                                     <ItemsControl FontWeight="Normal" ItemsSource="{Binding SelectedState.Action.Input}">
  382.                                         <ItemsControl.ItemTemplate>
  383.                                             <DataTemplate DataType="{x:Type local:BlackboardKeyViewModel}">
  384.                                                 <local:BlackBoardKeyEditorView Margin="0,0,0,2">
  385.                                                     <local:BlackBoardKeyEditorView.DataContext>
  386.                                                         <MultiBinding Converter="{local:BlackboardKeyEditorConverter CanChangeInputType=True}">
  387.                                                             <Binding Path="DataContext.Keys" Source="{StaticResource BlackboardProxy}" />
  388.                                                             <Binding BindsDirectlyToSource="True" />
  389.                                                         </MultiBinding>
  390.                                                     </local:BlackBoardKeyEditorView.DataContext>
  391.                                                 </local:BlackBoardKeyEditorView>
  392.                                             </DataTemplate>
  393.                                         </ItemsControl.ItemTemplate>
  394.                                     </ItemsControl>
  395.                                 </Expander>
  396.                                 <!--  OUTPUT  -->
  397.                                 <Expander
  398.                                       Grid.Row="2"
  399.                                       Grid.ColumnSpan="2"
  400.                                       Margin="0,5,0,0"
  401.                                       Padding="0,5,0,0"
  402.                                       BorderBrush="{DynamicResource BackgroundBrush}"
  403.                                       BorderThickness="0,0,0,1"
  404.                                       FontWeight="Bold"
  405.                                       Header="Output"
  406.                                       IsExpanded="True"
  407.                                       Visibility="{Binding SelectedState.Action.Output.Count, Converter={shared:BooleanToVisibilityConverter}}">
  408.                                     <Expander.Style>
  409.                                         <Style BasedOn="{StaticResource {x:Type Expander}}" TargetType="{x:Type Expander}">
  410.                                             <Setter Property="Tag" Value="{StaticResource ExpandRightIcon}" />
  411.                                             <Style.Triggers>
  412.                                                 <Trigger Property="IsExpanded" Value="True">
  413.                                                     <Setter Property="Tag" Value="{StaticResource ExpandDownIcon}" />
  414.                                                 </Trigger>
  415.                                             </Style.Triggers>
  416.                                         </Style>
  417.                                     </Expander.Style>
  418.                                     <ItemsControl FontWeight="Normal" ItemsSource="{Binding SelectedState.Action.Output}">
  419.                                         <ItemsControl.ItemTemplate>
  420.                                             <DataTemplate DataType="{x:Type local:BlackboardKeyViewModel}">
  421.                                                 <local:BlackBoardKeyEditorView Margin="0,0,0,2">
  422.                                                     <local:BlackBoardKeyEditorView.DataContext>
  423.                                                         <MultiBinding Converter="{local:BlackboardKeyEditorConverter CanChangeInputType=False}">
  424.                                                             <Binding Path="DataContext.Keys" Source="{StaticResource BlackboardProxy}" />
  425.                                                             <Binding BindsDirectlyToSource="True" />
  426.                                                         </MultiBinding>
  427.                                                     </local:BlackBoardKeyEditorView.DataContext>
  428.                                                 </local:BlackBoardKeyEditorView>
  429.                                             </DataTemplate>
  430.                                         </ItemsControl.ItemTemplate>
  431.                                     </ItemsControl>
  432.                                 </Expander>
  433.                                 <Grid Grid.Row="3" Grid.ColumnSpan="2" Margin="0 50 0 0" IsSharedSizeScope="True">
  434.                                     <Grid.RowDefinitions>
  435.                                         <RowDefinition Height="Auto" />
  436.                                         <RowDefinition Height="Auto" />
  437.                                         <RowDefinition />
  438.                                     </Grid.RowDefinitions>
  439.                                     <Grid>
  440.                                         <Grid.ColumnDefinitions>
  441.                                             <ColumnDefinition Width="*" />
  442.                                             <ColumnDefinition Width="Auto" />
  443.                                         </Grid.ColumnDefinitions>
  444.                                         <shared:EditableTextBlock
  445.                                                   FontSize="16"
  446.                                                   FontWeight="Bold"
  447.                                                   Foreground="{DynamicResource ForegroundBrush}"
  448.                                                   IsEditing="{Binding IsChecked, ElementName=EditName}"
  449.                                                   MaxLength="20"
  450.                                                   Text="{Binding Name}" />
  451.                                         <StackPanel Grid.Column="1" Orientation="Horizontal">
  452.                                             <CheckBox
  453.                                                  x:Name="EditName"
  454.                                                  Content="{StaticResource EditIcon}"
  455.                                                  Style="{StaticResource IconCheckBox}"
  456.                                                  ToolTip="修改参数名称" />
  457.                                             <Button
  458.                                                  Command="{Binding SelectedState.Action.AddKeyCommand}"
  459.                                                  Content="{StaticResource AddKeyIcon}"
  460.                                                  Style="{StaticResource IconButton}"
  461.                                                  ToolTip="添加新参数" />
  462.                                         </StackPanel>
  463.                                     </Grid>
  464.                                     <Separator
  465.                                           Grid.Row="1"
  466.                                           Width="Auto"
  467.                                           Height="2"
  468.                                           Margin="0,2,0,10" />
  469.                                     <ScrollViewer
  470.                                           Grid.Row="2"
  471.                                           HorizontalScrollBarVisibility="Auto"
  472.                                           VerticalScrollBarVisibility="Auto">
  473.                                         <ItemsControl ItemsSource="{Binding SelectedState.Action.ConfigParameter}">
  474.                                             <ItemsControl.ItemTemplate>
  475.                                                 <DataTemplate DataType="{x:Type local:BlackboardKeyViewModel}">
  476.                                                     <Grid Margin="0,0,0,2">
  477.                                                         <Grid.ColumnDefinitions>
  478.                                                             <ColumnDefinition />
  479.                                                             <ColumnDefinition SharedSizeGroup="Actions" />
  480.                                                         </Grid.ColumnDefinitions>
  481.                                                         <local:BlackBoardKeyEditorView>
  482.                                                             <local:BlackBoardKeyEditorView.DataContext>
  483.                                                                 <MultiBinding Converter="{local:BlackboardKeyEditorConverter CanChangeInputType=False}">
  484.                                                                     <Binding Path="DataContext.ConfigParameter" Source="{StaticResource BlackboardProxy}" />
  485.                                                                     <Binding BindsDirectlyToSource="True" />
  486.                                                                 </MultiBinding>
  487.                                                             </local:BlackBoardKeyEditorView.DataContext>
  488.                                                         </local:BlackBoardKeyEditorView>
  489.                                                         <StackPanel Grid.Column="3" Orientation="Horizontal">
  490.                                                             <CheckBox
  491.                                                                  x:Name="EditKeyName"
  492.                                                                  Content="{StaticResource EditIcon}"
  493.                                                                  Style="{StaticResource IconCheckBox}"
  494.                                                                  ToolTip="修改参数名称" />
  495.                                                             <Button
  496.                                                                  Command="{Binding DataContext.SelectedState.Action.RemoveKeyCommand, Source={StaticResource EditorProxy}}"
  497.                                                                  CommandParameter="{Binding}"
  498.                                                                  Content="{StaticResource RemoveKeyIcon}"
  499.                                                                  Style="{StaticResource IconButton}" />
  500.                                                         </StackPanel>
  501.                                                     </Grid>
  502.                                                 </DataTemplate>
  503.                                             </ItemsControl.ItemTemplate>
  504.                                         </ItemsControl>
  505.                                     </ScrollViewer>
  506.                                 </Grid>
  507.                             </Grid>
  508.                         </ScrollViewer>
  509.                         <ScrollViewer
  510.                               Grid.Row="2"
  511.                               VerticalScrollBarVisibility="Auto"
  512.                               Visibility="{Binding SelectedState.TargetType, Converter={StaticResource TargetTypeToVisibilityConverter}}">
  513.                             <Grid IsSharedSizeScope="True" VerticalAlignment="Top">
  514.                                 <Grid.ColumnDefinitions>
  515.                                     <ColumnDefinition Width="Auto"/>
  516.                                     <ColumnDefinition/>
  517.                                 </Grid.ColumnDefinitions>
  518.                                 <TextBlock Grid.Column="0" Text="编号" Margin="0,5,10,0"/>
  519.                                 <TextBox Grid.Column="1" Height="25" Text="{Binding SelectedState.Code}" IsEnabled="False"/>
  520.                             </Grid>
  521.                         </ScrollViewer>
  522.                     </Grid>
  523.                     <!-- Export/Import -->
  524.                     <Grid Grid.Row="2">
  525.                         <Grid.RowDefinitions>
  526.                             <RowDefinition Height="Auto" />
  527.                             <RowDefinition Height="Auto" />
  528.                             <RowDefinition />
  529.                         </Grid.RowDefinitions>
  530.                         <!--  NAME  -->
  531.                         <TextBlock
  532.                      FontSize="16"
  533.                      FontWeight="Bold"
  534.                      Foreground="{DynamicResource ForegroundBrush}"
  535.                      Text="方案导入/导出" />
  536.                         <Separator
  537.                      Grid.Row="1"
  538.                      Width="Auto"
  539.                      Height="2"
  540.                      Margin="0,2,0,5" />
  541.                         <Border Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top"
  542.                      Background="{DynamicResource PanelBackgroundBrush}"
  543.                      BorderThickness="0,0,0,1"
  544.                      CornerRadius="2"
  545.                      Height="40">
  546.                             <StackPanel Orientation="Horizontal" Height="40">
  547.                                 <Button Margin="10,0,10,0" Command="{Binding SaveCommand}"                    
  548.                                  Content="{StaticResource SaveIcon}"
  549.                                  Style="{StaticResource IconButton}"
  550.                                  ToolTip="Save" Cursor="Hand" Height="40"/>
  551.                                 <Button Margin="10,0,10,0" Command="{Binding ExportSchemeCommand}"                    
  552.                                  Content="{StaticResource ExportIcon}"
  553.                                  Style="{StaticResource IconButton}"
  554.                                  ToolTip="Export" Cursor="Hand" Height="40"/>
  555.                                 <Button Margin="10,0,10,0" Command="{Binding ImportSchemeCommand}"                    
  556.                                  Content="{StaticResource ImportIcon}"
  557.                                  Style="{StaticResource IconButton}"
  558.                                  ToolTip="Import" Cursor="Hand" Height="40"/>
  559.                             </StackPanel>
  560.                         </Border>
  561.                     </Grid>
  562.                 </Grid>
  563.             </Border>
  564.         </Expander>
  565.     </Grid>
  566. </UserControl>
复制代码
 精炼重要点为
  1. <h:Interaction.Triggers>
  2.     <h:EventTrigger EventName="Drop">
  3.         <h:CallMethodAction TargetObject="{Binding}"
  4.                             MethodName="nodify_Drop"/>
  5.     </h:EventTrigger>
  6. </h:Interaction.Triggers>
  7. <ListBox x:Name="CtlList" ItemsSource="{Binding ThumbList}" Background="Transparent"
  8.          ItemTemplate="{StaticResource ToolBoxStyle}" SelectedItem="{Binding ThumbSelectedItem}" BorderThickness="0">
  9.     <h:Interaction.Triggers>
  10.         <h:EventTrigger EventName="PreviewMouseMove">
  11.             <h:CallMethodAction MethodName="CtlList_PreviewMouseMove"
  12.                                 TargetObject="{Binding ElementName=custom,Path=DataContext}"/>
  13.         </h:EventTrigger>
  14.     </h:Interaction.Triggers>
  15. </ListBox>
复制代码
 其中Nodify的属性可参考此链接查察
第八节:Nodify 编辑器属性-CSDN博客
内里有编辑器的一些简介

CustomInterfaceViewModel.cs
  1. //可通过拖拽复制控件
  2. public void CtlList_PreviewMouseMove(object sender, MouseEventArgs e)
  3. {
  4.     if (ThumbSelectedItem != null && e.LeftButton == MouseButtonState.Pressed)
  5.     {
  6.         DragDrop.DoDragDrop((DependencyObject)sender, ThumbSelectedItem, DragDropEffects.Copy);
  7.     }
  8. }
  9. //nodify 放大缩小、平移后鼠标放在哪个位置  控件就显示在哪个位置
  10. //最重要的就是方法内前四句代码
  11. //p = new Point(Math.Round((p.X - editor.ViewportTransform.Value.OffsetX) / scale,0), Math.Round((p.Y - editor.ViewportTransform.Value.OffsetY) / scale,0));
  12. public void nodify_Drop(object sender, DragEventArgs e)
  13. {
  14.     var editor = sender as NodifyEditor;              
  15.     Point p = e.GetPosition(editor);
  16.     double scale = editor.ViewportZoom;
  17.     p = new Point(Math.Round((p.X - editor.ViewportTransform.Value.OffsetX) / scale,0), Math.Round((p.Y - editor.ViewportTransform.Value.OffsetY) / scale,0));
  18.     if (ThumbSelectedItem.TypeName == "Button")
  19.     {
  20.         States.Add(new CustomViewModel()
  21.         {
  22.             Name = "New Button",
  23.             IsRenaming = true,
  24.             Location = p,
  25.             ActionReference = Blackboard.Actions.Count > 0 ? Blackboard.Actions[0] : null,
  26.             TargetType = ThumbSelectedItem.TypeName
  27.         });
  28.     }
  29.     else if (ThumbSelectedItem.TypeName == "TextBox")
  30.     {
  31.         States.Add(new CustomViewModel
  32.         {
  33.             Code = GenerateUniqueRandomCode(1, 100),
  34.             Name = "New TextBox",
  35.             IsRenaming = true,
  36.             Location = p,
  37.             TargetType = "TextBox"
  38.         });
  39.     }
  40.     else
  41.     {
  42.         States.Add(new CustomViewModel
  43.         {
  44.             Name = "New TextBlock",
  45.             IsRenaming = true,
  46.             Location = p,
  47.             TargetType = "TextBlock"
  48.         });
  49.     }
  50.     e.Handled = true;
  51. }
复制代码
示例图
     Nodify添加拖拽事件,经过放大缩小、平移后获得控件坐标点
  

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

万万哇

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表