解决Nodify框架因自带放大缩小、平移功能导致拖拽添加的控件无法准确在鼠标放下的位置显示控件

news2024/11/16 3:28:42

ViewModel中写具体关键的几段代码:

var editor = sender as NodifyEditor;              

     Point p = e.GetPosition(editor);
     //放大缩小比例
     double scale = editor.ViewportZoom;

     //经过放大缩小、平移后获得坐标点位置
     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

<UserControl x:Class="Ueyes.Intergration.AgingEditor.View.CustomInterfaceView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:Ueyes.Intergration.AgingEditor" 
             xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
             xmlns:nodify="https://miroiu.github.io/nodify" 
             xmlns:shared="clr-namespace:Ueyes.Intergration.AgingEditor.Share;assembly=Ueyes.Intergration.AgingEditor.Share" 
             xmlns:h="http://schemas.microsoft.com/xaml/behaviors"
             mc:Ignorable="d" Name="custom"
             d:DesignHeight="800" d:DesignWidth="1000">
    <UserControl.Resources>
        <shared:TargetTypeToVisibilityConverter x:Key="TargetTypeToVisibilityConverter"/>
        <shared:BindingProxy x:Key="EditorProxy" DataContext="{Binding}" />
        <shared:BindingProxy x:Key="BlackboardProxy" DataContext="{Binding SelectedState.Action}" />

        <DataTemplate x:Key="ToolBoxStyle">
            <Grid Margin="2" Background="Transparent">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="30"/>
                    <ColumnDefinition/>
                </Grid.ColumnDefinitions>
                <iconPacks:PackIconMaterial x:Name="icon" Kind="Ellipse" BorderThickness="1" VerticalAlignment="Stretch" Width="24" HorizontalAlignment="Stretch"/>
                <TextBlock x:Name="txt" Grid.Column="1" Text="{Binding TypeName}" Margin="4"/>
            </Grid>

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding TypeName}" Value="Button">
                    <Setter Property="Kind" TargetName="icon" Value="GestureTapButton"/>
                    <Setter Property="Text" TargetName="txt" Value="{Binding Header}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding TypeName}" Value="TextBox">
                    <Setter Property="Kind" TargetName="icon" Value="Numeric8Box"/>
                    <Setter Property="Text" TargetName="txt" Value="{Binding Header}"/>
                </DataTrigger>
                <DataTrigger Binding="{Binding TypeName}" Value="TextBlock">
                    <Setter Property="Kind" TargetName="icon" Value="FormatText"/>
                    <Setter Property="Text" TargetName="txt" Value="{Binding Header}"/>
                </DataTrigger>       
            </DataTemplate.Triggers>
        </DataTemplate>

        <DataTemplate x:Key="ButtonTemplate">
            <Button Command="{Binding DataContext.ClickCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" CommandParameter="{Binding .}">
                <Button.Content>
                    <shared:EditableTextBlock IsEditable="{Binding IsEditable}"
                                    IsEditing="{Binding IsRenaming}" Text="{Binding Name}" />
                </Button.Content>
            </Button>
        </DataTemplate>

        <DataTemplate x:Key="TextBlockTemplate">
            <shared:EditableTextBlock IsEditable="{Binding IsEditable}" Foreground="Black" MaxLength="30"
                 IsEditing="{Binding IsRenaming}" Text="{Binding Name}" />
        </DataTemplate>

        <DataTemplate x:Key="TextBoxTemplate">
            <TextBox Text="{Binding Name}" IsEnabled="{Binding IsEditable}" MinHeight="25" MaxLength="30"/>
        </DataTemplate>

    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition />
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <nodify:NodifyEditor x:Name="Editor"  Grid.Column="1" Background="White" 
                             ItemsSource="{Binding States}" AllowDrop="True"
                             SelectedItem="{Binding SelectedState}" DisableZooming="False" DisablePanning="False"
                             SelectedItems="{Binding SelectedStates}">
            <h:Interaction.Triggers>
                <h:EventTrigger EventName="Drop">
                    <h:CallMethodAction TargetObject="{Binding}"
                                        MethodName="nodify_Drop"/>
                  
                </h:EventTrigger>
            </h:Interaction.Triggers>
            
            <nodify:NodifyEditor.ItemTemplate>
                <DataTemplate DataType="{x:Type local:StateViewModel}">

                    <nodify:StateNode Anchor="{Binding Anchor, Mode=OneWayToSource}" Padding="10 12"
                                    Content="{Binding}" IsConnected="False" ToolTip="{Binding Location}">
                        <nodify:StateNode.ContentTemplate>
                            <DataTemplate DataType="{x:Type local:StateViewModel}">
                                <ContentControl Content="{Binding}" >
                                    <ContentControl.Style>
                                        <Style TargetType="{x:Type ContentControl}">
                                            <Style.Triggers>
                                                <DataTrigger Binding="{Binding TargetType}" Value="Button">
                                                    <Setter Property="ContentTemplate" Value="{StaticResource ButtonTemplate}" />
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding TargetType}" Value="TextBlock">
                                                    <Setter Property="ContentTemplate" Value="{StaticResource TextBlockTemplate}" />
                                                </DataTrigger>
                                                <DataTrigger Binding="{Binding TargetType}" Value="TextBox">
                                                    <Setter Property="ContentTemplate" Value="{StaticResource TextBoxTemplate}" />
                                                </DataTrigger>
                                            </Style.Triggers>
                                        </Style>
                                    </ContentControl.Style>
                                </ContentControl>
                            </DataTemplate>
                        </nodify:StateNode.ContentTemplate>
                        <nodify:StateNode.Style>
                            <Style BasedOn="{StaticResource {x:Type nodify:StateNode}}" TargetType="{x:Type nodify:StateNode}">
                                <Setter Property="BorderThickness" Value="0"/>
                                <Style.Triggers>
                                    <DataTrigger Binding="{Binding TargetType}" Value="Button">
                                        <Setter Property="Background" Value="White" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding TargetType}" Value="TextBlock">
                                        <Setter Property="Foreground" Value="Black"/>
                                        <Setter Property="Background" Value="White" />
                                    </DataTrigger>
                                    <DataTrigger Binding="{Binding TargetType}" Value="TextBox">
                                        <Setter Property="Background" Value="White" />
                                    </DataTrigger>
                                </Style.Triggers>
                            </Style>
                        </nodify:StateNode.Style>
                    </nodify:StateNode>

                </DataTemplate>
            </nodify:NodifyEditor.ItemTemplate>

            <nodify:NodifyEditor.ItemContainerStyle>
                <Style BasedOn="{StaticResource {x:Type nodify:ItemContainer}}" TargetType="{x:Type nodify:ItemContainer}">
                    <Setter Property="BorderBrush" Value="Transparent" />
                    <Setter Property="Location" Value="{Binding Location}" />
                    <Setter Property="ActualSize" Value="{Binding Size, Mode=OneWayToSource}" />
                    <Setter Property="ContextMenu">
                        <Setter.Value>
                            <ContextMenu DataContext="{Binding DataContext, Source={StaticResource EditorProxy}}">
                                <MenuItem
                                    Command="{Binding DeleteCommand}"
                                    Header="_Delete"
                                    Icon="{StaticResource DeleteIcon}" 
                                    InputGestureText="Delete"/>
                                <MenuItem
                                    Command="{Binding CopyCommand}"
                                    Header="_Copy"
                                    Icon="{StaticResource CopyIcon}"
                                    InputGestureText="Ctrl+D" />
                                <MenuItem
                                    Command="{Binding RenameCommand}"
                                    Header="_Rename"
                                    Icon="{StaticResource RenameIcon}" />
                                <MenuItem
                                    Command="{Binding EditableCommand}"
                                    Header="_IsEditable"
                                    Icon="{StaticResource EditIcon}" />
                                <!--<MenuItem
                                    Command="{Binding MoveCommand}"
                                    Header="_IsMove"
                                    Icon="{StaticResource EditIcon}" />-->
                                <MenuItem Header="_Alignment" Icon="{StaticResource AlignTopIcon}">
                                    <MenuItem
                                        Command="{x:Static nodify:EditorCommands.Align}"
                                        CommandParameter="Top"
                                        Header="_Top"
                                        Icon="{StaticResource AlignTopIcon}" />
                                    <MenuItem
                                        Command="{x:Static nodify:EditorCommands.Align}"
                                        CommandParameter="Left"
                                        Header="_Left"
                                        Icon="{StaticResource AlignLeftIcon}" />
                                    <MenuItem
                                        Command="{x:Static nodify:EditorCommands.Align}"
                                        CommandParameter="Bottom"
                                        Header="_Bottom"
                                        Icon="{StaticResource AlignBottomIcon}" />
                                    <MenuItem
                                        Command="{x:Static nodify:EditorCommands.Align}"
                                        CommandParameter="Right"
                                        Header="_Right"
                                        Icon="{StaticResource AlignRightIcon}" />
                                    <MenuItem
                                        Command="{x:Static nodify:EditorCommands.Align}"
                                        CommandParameter="Middle"
                                        Header="_Middle"
                                        Icon="{StaticResource AlignMiddleIcon}" />
                                    <MenuItem
                                        Command="{x:Static nodify:EditorCommands.Align}"
                                        CommandParameter="Center"
                                        Header="_Center"
                                        Icon="{StaticResource AlignCenterIcon}" />
                                </MenuItem>
                            </ContextMenu>
                        </Setter.Value>
                    </Setter>
                </Style>
            </nodify:NodifyEditor.ItemContainerStyle>

            <nodify:NodifyEditor.ContextMenu>
                <ContextMenu DataContext="{Binding DataContext, Source={StaticResource EditorProxy}}">
                    <MenuItem
                        Command="{Binding AddButtonCommand}"
                        CommandParameter="{Binding PlacementTarget.MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        Header="_Add Button"
                        Icon="{StaticResource AddStateIcon}"/>
                    <MenuItem
                        Command="{Binding AddTextBlockCommand}"
                        CommandParameter="{Binding PlacementTarget.MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        Header="_Add TextBlock"
                        Icon="{StaticResource AddStateIcon}"/>
                    <MenuItem
                        Command="{Binding AddTextBoxCommand}"
                        CommandParameter="{Binding PlacementTarget.MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type ContextMenu}}}"
                        Header="_Add TextBox"
                        Icon="{StaticResource AddStateIcon}"/>
                    <MenuItem
                        Command="{Binding DeleteCommand}"
                        Header="_Delete"
                        Icon="{StaticResource DeleteIcon}"
                        InputGestureText="Delete" />
                    <Separator Background="{DynamicResource BorderBrush}" />
                    <MenuItem
                        Command="{x:Static nodify:EditorCommands.SelectAll}"
                        Header="_Select All"
                        Icon="{StaticResource SelectAllIcon}"
                        InputGestureText="Ctrl+A" />
                </ContextMenu>
            </nodify:NodifyEditor.ContextMenu>

            <!--快捷键添加删除新模块操作-->
            <nodify:NodifyEditor.InputBindings>
                <KeyBinding Key="Delete" Command="{Binding DeleteCommand}" />
                <!--<KeyBinding
                        Key="A"
                        Command="{Binding AddStateCommand}"
                        CommandParameter="{Binding MouseLocation, RelativeSource={RelativeSource AncestorType={x:Type nodify:NodifyEditor}}}"
                        Modifiers="Shift" />-->
                <KeyBinding Command="{Binding CopyCommand}" 
                         Key="D" Modifiers="Ctrl"/>
                <KeyBinding Command="{x:Static nodify:EditorCommands.SelectAll}" 
                         Key="A" Modifiers="Ctrl"/>
            </nodify:NodifyEditor.InputBindings>

        </nodify:NodifyEditor>

        <Expander
               Padding="0,1,4,3"
               HorizontalAlignment="Left"
               HorizontalContentAlignment="Left"
               VerticalContentAlignment="Center"
               Background="{DynamicResource PanelBackgroundBrush}"
               ExpandDirection="Left"
               IsExpanded="True"
               Visibility="Visible">
            <Expander.Style>
                <Style BasedOn="{StaticResource {x:Type Expander}}" TargetType="{x:Type Expander}">
                    <Setter Property="Tag" Value="{StaticResource ExpandRightIcon}" />
                    <Style.Triggers>
                        <Trigger Property="IsExpanded" Value="True">
                            <Setter Property="Tag" Value="{StaticResource ExpandLeftIcon}" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Expander.Style>

            <Border
                 Width="450"
                 Padding="10"
                 HorizontalAlignment="Stretch"
                 BorderBrush="{DynamicResource BackgroundBrush}"
                 BorderThickness="1">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="3*"/>
                        <RowDefinition Height="6*" />
                        <RowDefinition Height="1*" />
                    </Grid.RowDefinitions>

                    <!--  TRANSITIONS  -->
                    <Grid
                 Grid.Row="0"
                 Margin="0,10,0,10"                        
                 Visibility="{Binding SelectedState, Converter={shared:BooleanToVisibilityConverter Negate=True}}">

                        <Grid VerticalAlignment="Top">
                            <ListBox x:Name="CtlList" ItemsSource="{Binding ThumbList}" Background="Transparent" 
                                     ItemTemplate="{StaticResource ToolBoxStyle}" SelectedItem="{Binding ThumbSelectedItem}" BorderThickness="0">
                                <h:Interaction.Triggers>
                                    <h:EventTrigger EventName="PreviewMouseMove">
                                        <h:CallMethodAction MethodName="CtlList_PreviewMouseMove"
                                                            TargetObject="{Binding ElementName=custom,Path=DataContext}"/>
                                    </h:EventTrigger>
                                </h:Interaction.Triggers>
                            </ListBox>
                            <!--<ItemsControl ItemsSource="{Binding ThumbList}">
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <Border Margin="5,3" Tag="{Binding TypeName}">
                                            <StackPanel Orientation="Horizontal">
                                                <iconPacks:PackIconMaterial x:Name="icon" Kind="GestureTapButton" BorderThickness="1" 
                                                                            Width="30" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"/>
                                                <TextBlock x:Name="txt" Grid.Column="1" Text="{Binding Header}" Margin="4"/>
                                            </StackPanel>
                                            <h:Interaction.Triggers>
                                                <h:EventTrigger EventName="MouseLeftButtonDown">
                                                    <h:CallMethodAction MethodName="Border_MouseLeftButtonDown"
                                                                        TargetObject="{Binding ElementName=custom,Path=DataContext}"/>
                                                </h:EventTrigger>
                                            </h:Interaction.Triggers>
                                        </Border>
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>-->
                        </Grid>
                    </Grid>

                    <!--  STATES  -->
                    <Grid Grid.Row="0" Grid.RowSpan="2" Margin="0,10,0,10" Visibility="{Binding SelectedState, Converter={shared:BooleanToVisibilityConverter}}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <!--  STATE NAME  -->
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="*" />
                                <ColumnDefinition Width="Auto" />
                            </Grid.ColumnDefinitions>
                            <shared:EditableTextBlock
                                     FontSize="16"
                                     FontWeight="Bold"
                                     Foreground="{DynamicResource ForegroundBrush}"
                                     IsEditable="{Binding SelectedState.IsEditable}"
                                     IsEditing="{Binding IsChecked, ElementName=EditStateName}"
                                     MaxLength="20"
                                     Text="{Binding SelectedState.Name}" />
                            <CheckBox
                                    x:Name="EditStateName"
                                    Grid.Column="1"
                                    Content="{StaticResource EditIcon}"
                                    Style="{StaticResource IconCheckBox}"
                                    Visibility="{Binding SelectedState.IsEditable, Converter={shared:BooleanToVisibilityConverter}}" />
                        </Grid>

                        <Separator
                              Grid.Row="1"
                              Width="Auto"
                              Height="2"
                              Margin="0,2,0,10"/>

                        <ScrollViewer
                              Grid.Row="2"
                              VerticalScrollBarVisibility="Auto"
                              Visibility="{Binding SelectedState.Action, Converter={shared:BooleanToVisibilityConverter}}">
                            <Grid IsSharedSizeScope="True">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                    <ColumnDefinition />
                                </Grid.ColumnDefinitions>
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition Height="Auto" />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <!--  ACTION  -->
                                <TextBlock
                                     Margin="0,0,10,0"
                                     VerticalAlignment="Center"
                                     Text="操作" />
                                <ComboBox
                                     Grid.Column="1"
                                     DisplayMemberPath="Name"
                                     IsEnabled="{Binding SelectedState.IsEditable}"
                                     ItemsSource="{Binding Blackboard.Actions}"
                                     SelectedItem="{Binding SelectedState.ActionReference}" 
                                     />

                                <!--  INPUT  -->
                                <Expander
                                     Grid.Row="1"
                                     Grid.ColumnSpan="2"
                                     Margin="0,5,0,0"
                                     Padding="0,5,0,0"
                                     BorderBrush="{DynamicResource BackgroundBrush}"
                                     BorderThickness="0,0,0,1"
                                     FontWeight="Bold"
                                     Header="Input"
                                     IsExpanded="True"
                                     Visibility="{Binding SelectedState.Action.Input.Count, Converter={shared:BooleanToVisibilityConverter}}">
                                    <Expander.Style>
                                        <Style BasedOn="{StaticResource {x:Type Expander}}" TargetType="{x:Type Expander}">
                                            <Setter Property="Tag" Value="{StaticResource ExpandRightIcon}" />
                                            <Style.Triggers>
                                                <Trigger Property="IsExpanded" Value="True">
                                                    <Setter Property="Tag" Value="{StaticResource ExpandDownIcon}" />
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Expander.Style>
                                    <ItemsControl FontWeight="Normal" ItemsSource="{Binding SelectedState.Action.Input}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type local:BlackboardKeyViewModel}">
                                                <local:BlackBoardKeyEditorView Margin="0,0,0,2">
                                                    <local:BlackBoardKeyEditorView.DataContext>
                                                        <MultiBinding Converter="{local:BlackboardKeyEditorConverter CanChangeInputType=True}">
                                                            <Binding Path="DataContext.Keys" Source="{StaticResource BlackboardProxy}" />
                                                            <Binding BindsDirectlyToSource="True" />
                                                        </MultiBinding>
                                                    </local:BlackBoardKeyEditorView.DataContext>
                                                </local:BlackBoardKeyEditorView>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </Expander>
                                <!--  OUTPUT  -->
                                <Expander
                                      Grid.Row="2"
                                      Grid.ColumnSpan="2"
                                      Margin="0,5,0,0"
                                      Padding="0,5,0,0"
                                      BorderBrush="{DynamicResource BackgroundBrush}"
                                      BorderThickness="0,0,0,1"
                                      FontWeight="Bold"
                                      Header="Output"
                                      IsExpanded="True"
                                      Visibility="{Binding SelectedState.Action.Output.Count, Converter={shared:BooleanToVisibilityConverter}}">
                                    <Expander.Style>
                                        <Style BasedOn="{StaticResource {x:Type Expander}}" TargetType="{x:Type Expander}">
                                            <Setter Property="Tag" Value="{StaticResource ExpandRightIcon}" />
                                            <Style.Triggers>
                                                <Trigger Property="IsExpanded" Value="True">
                                                    <Setter Property="Tag" Value="{StaticResource ExpandDownIcon}" />
                                                </Trigger>
                                            </Style.Triggers>
                                        </Style>
                                    </Expander.Style>
                                    <ItemsControl FontWeight="Normal" ItemsSource="{Binding SelectedState.Action.Output}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate DataType="{x:Type local:BlackboardKeyViewModel}">
                                                <local:BlackBoardKeyEditorView Margin="0,0,0,2">
                                                    <local:BlackBoardKeyEditorView.DataContext>
                                                        <MultiBinding Converter="{local:BlackboardKeyEditorConverter CanChangeInputType=False}">
                                                            <Binding Path="DataContext.Keys" Source="{StaticResource BlackboardProxy}" />
                                                            <Binding BindsDirectlyToSource="True" />
                                                        </MultiBinding>
                                                    </local:BlackBoardKeyEditorView.DataContext>
                                                </local:BlackBoardKeyEditorView>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </Expander>

                                <Grid Grid.Row="3" Grid.ColumnSpan="2" Margin="0 50 0 0" IsSharedSizeScope="True">
                                    <Grid.RowDefinitions>
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition Height="Auto" />
                                        <RowDefinition />
                                    </Grid.RowDefinitions>

                                    <Grid>
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*" />
                                            <ColumnDefinition Width="Auto" />
                                        </Grid.ColumnDefinitions>
                                        <shared:EditableTextBlock
                                                  FontSize="16"
                                                  FontWeight="Bold"
                                                  Foreground="{DynamicResource ForegroundBrush}"
                                                  IsEditing="{Binding IsChecked, ElementName=EditName}"
                                                  MaxLength="20"
                                                  Text="{Binding Name}" />

                                        <StackPanel Grid.Column="1" Orientation="Horizontal">
                                            <CheckBox
                                                 x:Name="EditName"
                                                 Content="{StaticResource EditIcon}"
                                                 Style="{StaticResource IconCheckBox}"
                                                 ToolTip="修改参数名称" />
                                            <Button
                                                 Command="{Binding SelectedState.Action.AddKeyCommand}"
                                                 Content="{StaticResource AddKeyIcon}"
                                                 Style="{StaticResource IconButton}"
                                                 ToolTip="添加新参数" />
                                        </StackPanel>
                                    </Grid>

                                    <Separator
                                          Grid.Row="1"
                                          Width="Auto"
                                          Height="2"
                                          Margin="0,2,0,10" />

                                    <ScrollViewer
                                          Grid.Row="2"
                                          HorizontalScrollBarVisibility="Auto"
                                          VerticalScrollBarVisibility="Auto">
                                        <ItemsControl ItemsSource="{Binding SelectedState.Action.ConfigParameter}">
                                            <ItemsControl.ItemTemplate>
                                                <DataTemplate DataType="{x:Type local:BlackboardKeyViewModel}">
                                                    <Grid Margin="0,0,0,2">
                                                        <Grid.ColumnDefinitions>
                                                            <ColumnDefinition />
                                                            <ColumnDefinition SharedSizeGroup="Actions" />
                                                        </Grid.ColumnDefinitions>

                                                        <local:BlackBoardKeyEditorView>
                                                            <local:BlackBoardKeyEditorView.DataContext>
                                                                <MultiBinding Converter="{local:BlackboardKeyEditorConverter CanChangeInputType=False}">
                                                                    <Binding Path="DataContext.ConfigParameter" Source="{StaticResource BlackboardProxy}" />
                                                                    <Binding BindsDirectlyToSource="True" />
                                                                </MultiBinding>
                                                            </local:BlackBoardKeyEditorView.DataContext>
                                                        </local:BlackBoardKeyEditorView>

                                                        <StackPanel Grid.Column="3" Orientation="Horizontal">
                                                            <CheckBox
                                                                 x:Name="EditKeyName"
                                                                 Content="{StaticResource EditIcon}"
                                                                 Style="{StaticResource IconCheckBox}"
                                                                 ToolTip="修改参数名称" />
                                                            <Button
                                                                 Command="{Binding DataContext.SelectedState.Action.RemoveKeyCommand, Source={StaticResource EditorProxy}}"
                                                                 CommandParameter="{Binding}"
                                                                 Content="{StaticResource RemoveKeyIcon}"
                                                                 Style="{StaticResource IconButton}" />
                                                        </StackPanel>
                                                    </Grid>
                                                </DataTemplate>
                                            </ItemsControl.ItemTemplate>
                                        </ItemsControl>
                                    </ScrollViewer>
                                </Grid>





                            </Grid>
                        </ScrollViewer>


                        <ScrollViewer
                              Grid.Row="2"
                              VerticalScrollBarVisibility="Auto"
                              Visibility="{Binding SelectedState.TargetType, Converter={StaticResource TargetTypeToVisibilityConverter}}">
                            <Grid IsSharedSizeScope="True" VerticalAlignment="Top">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/>
                                    <ColumnDefinition/>
                                </Grid.ColumnDefinitions>
                                <TextBlock Grid.Column="0" Text="编号" Margin="0,5,10,0"/>
                                <TextBox Grid.Column="1" Height="25" Text="{Binding SelectedState.Code}" IsEnabled="False"/>
                            </Grid>
                        </ScrollViewer>


                    </Grid>


                    <!-- Export/Import -->
                    <Grid Grid.Row="2">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <!--  NAME  -->

                        <TextBlock
                     FontSize="16"
                     FontWeight="Bold"
                     Foreground="{DynamicResource ForegroundBrush}"
                     Text="方案导入/导出" />

                        <Separator
                     Grid.Row="1"
                     Width="Auto"
                     Height="2"
                     Margin="0,2,0,5" />

                        <Border Grid.Row="2" HorizontalAlignment="Left" VerticalAlignment="Top"
                     Background="{DynamicResource PanelBackgroundBrush}"
                     BorderThickness="0,0,0,1"
                     CornerRadius="2"
                     Height="40">
                            <StackPanel Orientation="Horizontal" Height="40">
                                <Button Margin="10,0,10,0" Command="{Binding SaveCommand}"                    
                                 Content="{StaticResource SaveIcon}"
                                 Style="{StaticResource IconButton}"
                                 ToolTip="Save" Cursor="Hand" Height="40"/>
                                <Button Margin="10,0,10,0" Command="{Binding ExportSchemeCommand}"                    
                                 Content="{StaticResource ExportIcon}"
                                 Style="{StaticResource IconButton}"
                                 ToolTip="Export" Cursor="Hand" Height="40"/>
                                <Button Margin="10,0,10,0" Command="{Binding ImportSchemeCommand}"                    
                                 Content="{StaticResource ImportIcon}"
                                 Style="{StaticResource IconButton}"
                                 ToolTip="Import" Cursor="Hand" Height="40"/>
                            </StackPanel>
                        </Border>
                    </Grid>
                </Grid>
            </Border>
        </Expander>
    </Grid>
</UserControl>

 精炼重要点为

<h:Interaction.Triggers>
    <h:EventTrigger EventName="Drop">
        <h:CallMethodAction TargetObject="{Binding}"
                            MethodName="nodify_Drop"/>
    </h:EventTrigger>
</h:Interaction.Triggers>


<ListBox x:Name="CtlList" ItemsSource="{Binding ThumbList}" Background="Transparent" 
         ItemTemplate="{StaticResource ToolBoxStyle}" SelectedItem="{Binding ThumbSelectedItem}" BorderThickness="0">
    <h:Interaction.Triggers>
        <h:EventTrigger EventName="PreviewMouseMove">
            <h:CallMethodAction MethodName="CtlList_PreviewMouseMove"
                                TargetObject="{Binding ElementName=custom,Path=DataContext}"/>
        </h:EventTrigger>
    </h:Interaction.Triggers>
</ListBox>

 其中Nodify的属性可参考此链接查看

第八节:Nodify 编辑器属性-CSDN博客

里面有编辑器的一些简介

CustomInterfaceViewModel.cs

//可通过拖拽复制控件
public void CtlList_PreviewMouseMove(object sender, MouseEventArgs e)
{
    if (ThumbSelectedItem != null && e.LeftButton == MouseButtonState.Pressed)
    {
        DragDrop.DoDragDrop((DependencyObject)sender, ThumbSelectedItem, DragDropEffects.Copy);
    }
}


//nodify 放大缩小、平移后鼠标放在哪个位置  控件就显示在哪个位置
//最重要的就是方法内前四句代码
//p = new Point(Math.Round((p.X - editor.ViewportTransform.Value.OffsetX) / scale,0), Math.Round((p.Y - editor.ViewportTransform.Value.OffsetY) / scale,0));

public void nodify_Drop(object sender, DragEventArgs e)
{
    var editor = sender as NodifyEditor;              

    Point p = e.GetPosition(editor);

    double scale = editor.ViewportZoom;

    p = new Point(Math.Round((p.X - editor.ViewportTransform.Value.OffsetX) / scale,0), Math.Round((p.Y - editor.ViewportTransform.Value.OffsetY) / scale,0));

    if (ThumbSelectedItem.TypeName == "Button")
    {
        States.Add(new CustomViewModel()
        {
            Name = "New Button",
            IsRenaming = true,
            Location = p,
            ActionReference = Blackboard.Actions.Count > 0 ? Blackboard.Actions[0] : null,
            TargetType = ThumbSelectedItem.TypeName
        });
    }
    else if (ThumbSelectedItem.TypeName == "TextBox")
    {
        States.Add(new CustomViewModel
        {
            Code = GenerateUniqueRandomCode(1, 100),
            Name = "New TextBox",
            IsRenaming = true,
            Location = p,
            TargetType = "TextBox"
        });
    }
    else
    {
        States.Add(new CustomViewModel
        {
            Name = "New TextBlock",
            IsRenaming = true,
            Location = p,
            TargetType = "TextBlock"
        });
    }
    e.Handled = true;

}


示例图

Nodify添加拖拽事件,经过放大缩小、平移后获得控件坐标点

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2161253.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

搜维尔科技:OptiTrack采集到的平衡数据,并对人形机器人进行编程,可以确保机器人的动作精度和准确性

OptiTrack具备高精度以及远追踪距离的双层特点&#xff0c;其捕捉范围最远可达91m&#xff0c;是大型场地&#xff08;如体育馆、足球场、虚拟拍摄制作棚等&#xff09;捕捉的最佳选择。 OptiTrack光学动作捕捉系统是目前全球市占率较高的全身动捕产品&#xff0c;可实现精度误…

第十六章 Javamail发送邮件

目录 一、邮件发送原理和流程图 二、Java发送邮件基本步骤 三、QQ邮箱授权码获取 四、示例代码 注&#xff1a;本章内容仅作为了解JavaMail邮件收发的基本原理&#xff0c;不建议作为实际项目使用&#xff0c;项目中建议通过SpringBoot项目加入mail的starter依赖来构建&am…

2.2 信道的极限容量

奈奎斯特定理 香农定理 &#x1f30f;总结

怎么抠图把杂乱的人全部擦除?分享1个简单方法

前言 在图像编辑中&#xff0c;抠图是一项基本而重要的技能。它允许我们从一张图片中提取出想要的部分&#xff0c;或者去除不需要的元素。今天&#xff0c;我将分享一个简单而有效的方法来抠图&#xff0c;特别是如何擦除图片中杂乱的人物。 工具介绍 在众多的抠图工具中&a…

【近源攻击】badusb上线cs

❤️博客主页&#xff1a; iknow181 &#x1f525;系列专栏&#xff1a; 网络安全、 Python、JavaSE、JavaWeb、CCNP &#x1f389;欢迎大家点赞&#x1f44d;收藏⭐评论✍ 0x01 实验前提 攻击设备&#xff1a;badusb cs服务器&#xff1a;公网部署了 cs 服务端 0x02 实验步骤 …

入耳式耳机戴久不舒服?真心劝你试试这五款骨传导耳机~

基于对运动耳机长时间的使用体验和细致研究&#xff0c;我有以下几点务实的建议想与大家交流&#xff1a;在做出购买决定之前&#xff0c;请多加思考&#xff0c;避免盲目追逐市场热点。有时候&#xff0c;那些突然风靡的网红耳机可能只是短暂的流行&#xff1b;同样&#xff0…

新学期月考成绩发布工具-易查分

老师们&#xff0c;新学期的第一次月考即将到来&#xff0c;是不是在想如何高效又安全地发布成绩呢&#xff1f;别担心&#xff0c;我来给你们介绍一个超实用的小工具——易查分小程序&#xff01; 新学期&#xff0c;新挑战&#xff0c;但发布成绩这件事&#xff0c;可以变得…

# Windows环境下VSCode + Jupyter + Conda的AI学习环境配置指南

Windows环境下VSCode Jupyter Conda的AI学习环境配置指南 目录 Windows环境下VSCode Jupyter Conda的AI学习环境配置指南 优点 1. 安装Anaconda 2. 安装Visual Studio Code 3. 在VSCode中配置Python环境 4. 安装和配置Jupyter 5. 创建和管理虚拟环境 6. 安装常用的…

通信工程学习:什么是VNF虚拟网络功能

VNF&#xff1a;虚拟网络功能 VNF&#xff08;Virtual Network Function&#xff09;即虚拟网络功能&#xff0c;是网络功能虚拟化&#xff08;NFV&#xff09;架构中的一个核心概念。VNF允许通过软件化和虚拟化的方式&#xff0c;将传统的网络设备功能&#xff08;如路由器、交…

CREO教程——2 绘制标准图纸

CREO教程——2 绘制标准图纸 说明&#xff1a;继承第一章设置好的配置文件&#xff0c;这一章进行学习分享如何定制自己的图纸图框&#xff0c;参考国家标准距&#xff0c;定制属于设计师或单位的通用图框。 1.设置工作目录 1.1设置工作目录 1.打开软件设置工作目录&#x…

MySQL按照经纬度排序 查询出商家信息

首先自己写公式算法&#xff0c;这个我们懒 就不写了&#xff0c;pass~ ST_Distance_Sphere用法和示例&#xff1a; 我们懒人使用MySQL自带的函数先看查询出的结果示例&#xff1a;示例代码(看代码直接跳这)&#xff1a;注意事项 我们懒人使用MySQL自带的函数 ST_Distance_Sphe…

scrapy spider框架download下来就可以用

一.通过命令行创建scrapy项目 1.scrapy startproject project_Spider 二.通过命令行创建spider 1.scrapy genspider firstspider 2.定义需要抓取的字段,在items.py文件中对目标字段进行定义 # Define here the models for your scraped items # # See documentation in: # …

Java面试篇基础部分-Semaphore及其用法详解

Semaphore 是一种基于计数的信号量&#xff0c;在定义信号量对象的时候可以设置一个阈值&#xff0c;然后基于这个阈值&#xff0c;多线程可以竞争访问信号量&#xff0c;线程竞争到许可的信号之后&#xff0c;开始执行具体的业务逻辑&#xff0c;业务逻辑在执行完成之后释放这…

程序员修炼之道 13:务实的项目

不记录&#xff0c;等于没读。 这里是我阅读《程序员修炼之道》这本书的记录和思考。 务实的团队 一个项目不只你一个人&#xff0c;就需要建立一些基本规则&#xff0c;并依次将项目的各部分分配出去。 程序员有点像猫&#xff1a;聪明、意志坚强、固执己见、独立、并且经常…

3. 函数

函数是 JavaScript 编程中最重要的工具之一。用一个值封装一段程序的概念有很多用途。它为我们提供了一种结构化大型程序的方法&#xff0c;可以减少重复&#xff0c;将名称与子程序关联起来&#xff0c;并将这些子程序相互隔离。 函数最明显的应用是定义新的词汇。在散文中创造…

一款前后端分离CRM客户关系管理系统,支持客户,商机,线索,合同,发票,审核,商品等功能(附源码)

前言 在当今竞争激烈的商业环境中&#xff0c;企业面临着各种挑战&#xff0c;其中包括如何更有效地管理和跟进潜在客户以提高销售业绩。传统的客户管理方式往往效率低下&#xff0c;无法实时更新客户-信息&#xff0c;导致销售机会流失。因此&#xff0c;市场上急需一款能够简…

计算机毕设选题推荐-基于python的电子健康信息分析系统【源码+文档+调试】

精彩专栏推荐订阅&#xff1a;在下方主页&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb; &#x1f496;&#x1f525;作者主页&#xff1a;计算机毕设木哥&#x1f525; &#x1f496; 文章目录 一、电子健康信息…

【解决虚拟机NAT联网】收藏这份教程就不用再辛苦找了

网上的教程一大堆&#xff0c;看的云里雾里&#xff0c;对于一个小白来说这里看懂了&#xff0c;下一步又看不懂了&#xff0c;一模一样的去设置也不一定成功。 解决办法01 恢复默认设置&#xff1a; 首先公布一个最基础的最直接最有效的恢复网络的办法&#xff1a; 关闭虚拟…

Python字典进阶:setdefault技巧让你的代码更优雅,用setdefault优化你的Python数据处理流程

推荐阅读&#xff1a; 数据科学的秘密武器&#xff1a;defaultdict——Python字典的自动化填充神器&#xff0c;让数据结构更灵活 一、什么是setdefault Python中的setdefault方法是字典&#xff08;dict&#xff09;类型的一个非常实用的方法&#xff0c;它允许开发者在尝试…

Invalid Executable The executable contains bitcode

Invalid Executable The executable contains bitcode xcode世界xcode16后&#xff0c;打包上传testflight时三方库报错&#xff1a;Invalid Executable - The executable ***.app/Frameworks/xxx.framework/xxx contains bitcode. 解决方案&#xff1a; 执行一下指令删除该f…