none
Gridの拡大縮小制限、移動制限をかけたいのですが上手くいきません。(WPF)

    質問

  • 2本の指でタッチした状態で拡大縮小をした際に、拡大最大値、縮小最小値を決め制限をかけたいのですがうまくいきません。

    現在確認できているパターンは勢いよく拡大縮小を行った場合です。その際に想定よりもGridが小さくなったり大きくなったりします。

    また、上手く実装ができなかったためソースコードがありませんが、WindowからGrid範囲外が表示されないように移動制限もかけたいと考えております。

    ご教授お願いいたします。

    2019年4月17日 0:17

回答

  • DeltaManipulationではなくCumulativeManipulationを使ってみる

    <Window x:Class="SampleClass"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:MyNamespace="clr-namespace:SAMPLE"
            mc:Ignorable="d"
            Title="sample" Height="650" Width="600" Background="Cornsilk" 
            MaxHeight="650" MaxWidth="600" MinHeight="535" MinWidth="484" 
            ManipulationStarting="Window_ManipulationStarting" 
            ManipulationDelta="Window_ManipulationDelta" 
            ManipulationCompleted="Window_ManipulationCompleted"
            ResizeMode="NoResize">
        <Window.Resources>
            <Style x:Key="HeaderCenterStyle" TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
        </Window.Resources>
        <Canvas x:Name="board" Height="550" Width="500" Background="Gray" OpacityMask="Gray" HorizontalAlignment="Center" VerticalAlignment="Center"
                IsManipulationEnabled="False" >
    
            <Grid x:Name="grdinner" HorizontalAlignment="Left" VerticalAlignment="Top" OpacityMask="Gray" Background="Orange" 
                  MinWidth="472" MaxWidth="700" Width="472" Height="500" 
                  IsManipulationEnabled="true" >
                
                <Button x:Name="btn1" Content="ボタン1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="90" Height="30" Margin="9,9,0,0" FontFamily="MS UI Gothic"/>
                <Label x:Name="Name" Content="項目1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="124,30,0,0" FontFamily="MS UI Gothic" FontSize="19.5" FontWeight="Bold" Height="40" Width="240" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" Background="Gray"/>
                <Label x:Name="Code" Content="項目2" Width="150" Height="15" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="70,102,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" FontFamily="MS UI Gothic" Background="Gray"/>
                <MyNamespace:commonTextBox1 x:Name="commonTextBox" HorizontalAlignment="Left" Height="21" Width="100" CmbText="" Grid.Column="1" Grid.Row="2" Margin="250,100,0,0" VerticalAlignment="Top" FontFamily="MS UI Gothic"/>
                <Button x:Name="btn2" Content="ボタン2" HorizontalAlignment="Left" Width="40" Height="25" Grid.Column="1" Grid.Row="2" Margin="380,100,0,0" VerticalAlignment="Top" FontFamily="MS UI Gothic"/>
                <DataGrid x:Name="DataGrid1" HorizontalAlignment="Left" Height="330" Width="460" AutoGenerateColumns="False" CanUserReorderColumns="False" IsReadOnly="True" Padding="0" VerticalAlignment="Top" FontFamily="MS UI Gothic" Margin="5,160,0,0" RowHeight="21" VerticalContentAlignment="Center" Canvas.Left="0" Canvas.Top="0">
                    <DataGrid.Resources>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                                        <Grid Background="{TemplateBinding Background}">
                                            <ContentPresenter VerticalAlignment="Center"/>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding MakerCd}" Header="項目1" Width="150" FontFamily="MS UI Gothic"/>
                        <DataGridTextColumn Binding="{Binding MakerNa}" Header="項目2" Width="*" FontFamily="MS UI Gothic" HeaderStyle="{StaticResource HeaderCenterStyle}"/>
                    </DataGrid.Columns>
                </DataGrid>
                <TextBlock x:Name="area" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Background="Gray" Width="134" Margin="320,6,0,0"><Run Text="x:初期"/><LineBreak/><Run Text="y:初期"/></TextBlock>
                <MyNamespace:clsComboBoxInput x:Name="clsComboI" Width="100" Height="21" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="9,50,0,0" IsManipulationEnabled="False"/>
            </Grid>
        </Canvas>
    </Window>
    Class SampleClass
        Sub New()
            ' この呼び出しはデザイナーで必要です。
            InitializeComponent()
    
            ' InitializeComponent() 呼び出しの後で初期化を追加します。
            AddHandler Me.DataGrid1.Loaded,
                Sub(s, e)
                    Dim sv As ScrollViewer = CType(Me.DataGrid1.Template.FindName("DG_ScrollViewer", Me.DataGrid1), ScrollViewer)
                    sv.IsManipulationEnabled = False
                End Sub
        End Sub
    
    
        Private Const scaleMin As Double = 0.5
        Private Const scaleMax As Double = 2
    
        Private target As FrameworkElement '操作対象
        Private originalMatrix As Matrix '開始時のMatrix
        Private focusedCombo As ComboBox
        Private Sub Window_ManipulationStarting(sender As Object, e As ManipulationStartingEventArgs)
            If target IsNot Nothing Then
                Return
            End If
    
            target = TryCast(e.OriginalSource, FrameworkElement)
            If target Is Nothing Then
                Return
            End If
    
            Me.focusedCombo = Nothing
            Dim focused = FocusManager.GetFocusedElement(Me)
            If TypeOf focused Is ComboBox Then
                Me.focusedCombo = TryCast(FocusManager.GetFocusedElement(Me), ComboBox)
                If Me.focusedCombo.IsDropDownOpen Then
                    Me.focusedCombo.IsDropDownOpen = False
                Else
                    Me.focusedCombo = Nothing
                End If
            End If
    
                Me.originalMatrix = CType(target.RenderTransform, MatrixTransform).Matrix
            e.ManipulationContainer = VisualTreeHelper.GetParent(target) '座標系を親のに
            e.Handled = True
        End Sub
    
        Private Sub Window_ManipulationDelta(sender As Object, e As ManipulationDeltaEventArgs)
            If target Is Nothing Then
                Return
            End If
    
            Dim parent As FrameworkElement = VisualTreeHelper.GetParent(target)
            Dim cloneMatrix As Matrix = Me.originalMatrix
    
            'オブジェクトの移動を行う。
            cloneMatrix.Translate(e.CumulativeManipulation.Translation.X, e.CumulativeManipulation.Translation.Y)
    
            'オブジェクトの拡大縮小を行う。
            Dim scale = Math.Max(e.CumulativeManipulation.Scale.X, e.CumulativeManipulation.Scale.Y)
    
            '拡縮範囲の制限
            Dim temp As Double = cloneMatrix.M11 * scale
            If temp < scaleMin Then
                scale = scaleMin / cloneMatrix.M11
            End If
            If scaleMax < temp Then
                scale = scaleMax / cloneMatrix.M11
            End If
            cloneMatrix.ScaleAt(scale, scale, e.ManipulationOrigin.X, e.ManipulationOrigin.Y)
            Debug.Print("TotalScale=" + cloneMatrix.M11.ToString())
    
            '親の座標に変換
            Dim ps(0 To 1) As Point
            ps(0) = New Point(0, 0)
            ps(1) = New Point(target.ActualWidth, target.ActualHeight)
            cloneMatrix.Transform(ps)
    
            'はみ出た部分を中に移動しなおし
            If parent.ActualWidth < ps(1).X Then
                cloneMatrix.Translate(parent.ActualWidth - ps(1).X, 0)
            ElseIf ps(0).X < 0 Then
                cloneMatrix.Translate(-ps(0).X, 0)
            End If
    
            If parent.ActualHeight < ps(1).Y Then
                cloneMatrix.Translate(0, parent.ActualHeight - ps(1).Y)
            ElseIf ps(0).Y < 0 Then
                cloneMatrix.Translate(0, -ps(0).Y)
            End If
    
            target.RenderTransform = New MatrixTransform(cloneMatrix)
        End Sub
    
        Private Sub Window_ManipulationCompleted(sender As Object, e As ManipulationCompletedEventArgs)
            If target Is Nothing Then
                Return
            End If
            target = Nothing
            If focusedCombo IsNot Nothing Then
                focusedCombo.IsDropDownOpen = True
            End If
            focusedCombo = Nothing
        End Sub
    End Class
    
    Class commonTextBox1
        Inherits TextBox
        Public Property CmbText As String
    End Class
    Class clsComboBoxInput
        Inherits ComboBox
    End Class



    個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)

    • 回答としてマーク WPFNN 2019年4月18日 8:26
    2019年4月17日 17:00

すべての返信

  • 2本の指でタッチした状態で拡大縮小をした際に、拡大最大値、縮小最小値を決め制限をかけたいのですがうまくいきません。

    現在確認できているパターンは勢いよく拡大縮小を行った場合です。その際に想定よりもGridが小さくなったり大きくなったりします。

    また、上手く実装ができなかったためソースコードがありませんが、WindowからGrid範囲外が表示されないように移動制限もかけたいと考えております。

    ご教授お願いいたします。

    ソースコードは次のようになります。

    よろしくお願いいたします。

    '指で動かしている時に発生するイベント
    Private Sub Window_ManipulationDelta(sender As Object, e As ManipulationDeltaEventArgs)
        Dim Rect = TryCast(e.OriginalSource, Grid)
        If Rect IsNot Nothing Then
            Dim rectsMatrix = (CType(Rect.RenderTransform, MatrixTransform)).Matrix
    
            'オブジェクトの移動を行う。
            rectsMatrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y)
    
            'オブジェクトの拡大縮小を行う。
            rectsMatrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y, _
                                e.ManipulationOrigin.X, e.ManipulationOrigin.Y)
    
            Dim scale = Math.Max(
            e.DeltaManipulation.Scale.X,
            e.DeltaManipulation.Scale.Y)
            grdinner.Width *= scale
            If (grdinner.Width < grdinner.MinWidth) Then
                grdinner.Width = grdinner.MinWidth
                Return
            End If
            If (grdinner.Width > grdinner.MaxWidth) Then
                grdinner.Width = grdinner.MaxWidth
                Return
            End If
            area.Text = String.Format("x:{0} y:{1}", grdinner.Width, grdinner.ActualWidth)
            Rect.RenderTransform = New MatrixTransform(rectsMatrix)
            e.Handled = True
        End If
    
    End Sub
    

    <Window
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:MyNamespace="clr-namespace:SAMPLE"
        xmlns:System="clr-namespace:System;assembly=mscorlib" x:Name="window"
        mc:Ignorable="d" x:Class="SampleClass"
        Title="サンプル" Height="535" Width="484" Background="Gray" MaxHeight="535" MaxWidth="484" MinHeight="535" MinWidth="484" ManipulationStarting="Window_ManipulationStarting" ManipulationDelta="Window_ManipulationDelta" ResizeMode="NoResize">
        <Window.Resources>
            <Style x:Key="HeaderCenterStyle" TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
        </Window.Resources>
        <Canvas x:Name="board" Height="500" Width="472" Background="Gray" OpacityMask="Gray" IsManipulationEnabled="True" HorizontalAlignment="Center" VerticalAlignment="Center">
            <Canvas.RenderTransform>
                <TransformGroup>
                    <MatrixTransform x:Name="matrixtransform">
                    <MatrixTransform.Matrix>
                        <Matrix OffsetX="0" OffsetY="0"/>
                    </MatrixTransform.Matrix>
                    </MatrixTransform>
                </TransformGroup>
            </Canvas.RenderTransform>
            <Grid x:Name="grdinner" HorizontalAlignment="Left" VerticalAlignment="Top" IsManipulationEnabled="True" Background="Gray" OpacityMask="Gray" MinWidth="472" MaxWidth="700" Width="472" Height="500">
                <Button x:Name="btn1" Content="ボタン1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="90" Height="30" Margin="9,9,0,0" FontFamily="MS UI Gothic"/>
                <Label x:Name="Name" Content="項目1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="124,30,0,0" FontFamily="MS UI Gothic" FontSize="19.5" FontWeight="Bold" Height="40" Width="240" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" Background="Gray"/>
                <Label x:Name="Code" Content="項目2" Width="150" Height="15" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="70,102,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" FontFamily="MS UI Gothic" Background="Gray"/>
                <MyNamespace:commonTextBox1 x:Name="commonTextBox" HorizontalAlignment="Left" Height="21" Width="100" CmbText="" Grid.Column="1" Grid.Row="2" Margin="250,100,0,0" VerticalAlignment="Top" FontFamily="MS UI Gothic"/>
                <Button x:Name="btn2" Content="ボタン2" HorizontalAlignment="Left" Width="40" Height="25" Grid.Column="1" Grid.Row="2" Margin="380,100,0,0" VerticalAlignment="Top" FontFamily="MS UI Gothic"/>
                <DataGrid x:Name="DataGrid1" HorizontalAlignment="Left" Height="330" Width="460" AutoGenerateColumns="False" CanUserReorderColumns="False" IsReadOnly="True" Padding="0" VerticalAlignment="Top" FontFamily="MS UI Gothic" Margin="5,160,0,0" RowHeight="21" VerticalContentAlignment="Center" Canvas.Left="0" Canvas.Top="0">
                    <DataGrid.Resources>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                                        <Grid Background="{TemplateBinding Background}">
                                            <ContentPresenter VerticalAlignment="Center"/>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding MakerCd}" Header="項目1" Width="150" FontFamily="MS UI Gothic"/>
                        <DataGridTextColumn Binding="{Binding MakerNa}" Header="項目2" Width="*" FontFamily="MS UI Gothic" HeaderStyle="{StaticResource HeaderCenterStyle}"/>
                    </DataGrid.Columns>
                </DataGrid>
                <TextBlock x:Name="area" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Background="Gray" Width="134" Margin="320,6,0,0"><Run Text="x:初期"/><LineBreak/><Run Text="y:初期"/></TextBlock>
                <MyNamespace:clsComboBoxInput x:Name="clsComboI" Width="100" Height="21" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="9,50,0,0" IsManipulationEnabled="False"/>
            </Grid>
        </Canvas>
    </Window>

    2019年4月17日 0:28
  • DeltaManipulationではなくCumulativeManipulationを使ってみる

    <Window x:Class="SampleClass"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:MyNamespace="clr-namespace:SAMPLE"
            mc:Ignorable="d"
            Title="sample" Height="650" Width="600" Background="Cornsilk" 
            MaxHeight="650" MaxWidth="600" MinHeight="535" MinWidth="484" 
            ManipulationStarting="Window_ManipulationStarting" 
            ManipulationDelta="Window_ManipulationDelta" 
            ManipulationCompleted="Window_ManipulationCompleted"
            ResizeMode="NoResize">
        <Window.Resources>
            <Style x:Key="HeaderCenterStyle" TargetType="{x:Type DataGridColumnHeader}">
                <Setter Property="HorizontalContentAlignment" Value="Center" />
            </Style>
        </Window.Resources>
        <Canvas x:Name="board" Height="550" Width="500" Background="Gray" OpacityMask="Gray" HorizontalAlignment="Center" VerticalAlignment="Center"
                IsManipulationEnabled="False" >
    
            <Grid x:Name="grdinner" HorizontalAlignment="Left" VerticalAlignment="Top" OpacityMask="Gray" Background="Orange" 
                  MinWidth="472" MaxWidth="700" Width="472" Height="500" 
                  IsManipulationEnabled="true" >
                
                <Button x:Name="btn1" Content="ボタン1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="90" Height="30" Margin="9,9,0,0" FontFamily="MS UI Gothic"/>
                <Label x:Name="Name" Content="項目1" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="124,30,0,0" FontFamily="MS UI Gothic" FontSize="19.5" FontWeight="Bold" Height="40" Width="240" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" Background="Gray"/>
                <Label x:Name="Code" Content="項目2" Width="150" Height="15" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="70,102,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Padding="0" FontFamily="MS UI Gothic" Background="Gray"/>
                <MyNamespace:commonTextBox1 x:Name="commonTextBox" HorizontalAlignment="Left" Height="21" Width="100" CmbText="" Grid.Column="1" Grid.Row="2" Margin="250,100,0,0" VerticalAlignment="Top" FontFamily="MS UI Gothic"/>
                <Button x:Name="btn2" Content="ボタン2" HorizontalAlignment="Left" Width="40" Height="25" Grid.Column="1" Grid.Row="2" Margin="380,100,0,0" VerticalAlignment="Top" FontFamily="MS UI Gothic"/>
                <DataGrid x:Name="DataGrid1" HorizontalAlignment="Left" Height="330" Width="460" AutoGenerateColumns="False" CanUserReorderColumns="False" IsReadOnly="True" Padding="0" VerticalAlignment="Top" FontFamily="MS UI Gothic" Margin="5,160,0,0" RowHeight="21" VerticalContentAlignment="Center" Canvas.Left="0" Canvas.Top="0">
                    <DataGrid.Resources>
                        <Style TargetType="DataGridCell">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type DataGridCell}">
                                        <Grid Background="{TemplateBinding Background}">
                                            <ContentPresenter VerticalAlignment="Center"/>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </DataGrid.Resources>
                    <DataGrid.Columns>
                        <DataGridTextColumn Binding="{Binding MakerCd}" Header="項目1" Width="150" FontFamily="MS UI Gothic"/>
                        <DataGridTextColumn Binding="{Binding MakerNa}" Header="項目2" Width="*" FontFamily="MS UI Gothic" HeaderStyle="{StaticResource HeaderCenterStyle}"/>
                    </DataGrid.Columns>
                </DataGrid>
                <TextBlock x:Name="area" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Top" Background="Gray" Width="134" Margin="320,6,0,0"><Run Text="x:初期"/><LineBreak/><Run Text="y:初期"/></TextBlock>
                <MyNamespace:clsComboBoxInput x:Name="clsComboI" Width="100" Height="21" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="9,50,0,0" IsManipulationEnabled="False"/>
            </Grid>
        </Canvas>
    </Window>
    Class SampleClass
        Sub New()
            ' この呼び出しはデザイナーで必要です。
            InitializeComponent()
    
            ' InitializeComponent() 呼び出しの後で初期化を追加します。
            AddHandler Me.DataGrid1.Loaded,
                Sub(s, e)
                    Dim sv As ScrollViewer = CType(Me.DataGrid1.Template.FindName("DG_ScrollViewer", Me.DataGrid1), ScrollViewer)
                    sv.IsManipulationEnabled = False
                End Sub
        End Sub
    
    
        Private Const scaleMin As Double = 0.5
        Private Const scaleMax As Double = 2
    
        Private target As FrameworkElement '操作対象
        Private originalMatrix As Matrix '開始時のMatrix
        Private focusedCombo As ComboBox
        Private Sub Window_ManipulationStarting(sender As Object, e As ManipulationStartingEventArgs)
            If target IsNot Nothing Then
                Return
            End If
    
            target = TryCast(e.OriginalSource, FrameworkElement)
            If target Is Nothing Then
                Return
            End If
    
            Me.focusedCombo = Nothing
            Dim focused = FocusManager.GetFocusedElement(Me)
            If TypeOf focused Is ComboBox Then
                Me.focusedCombo = TryCast(FocusManager.GetFocusedElement(Me), ComboBox)
                If Me.focusedCombo.IsDropDownOpen Then
                    Me.focusedCombo.IsDropDownOpen = False
                Else
                    Me.focusedCombo = Nothing
                End If
            End If
    
                Me.originalMatrix = CType(target.RenderTransform, MatrixTransform).Matrix
            e.ManipulationContainer = VisualTreeHelper.GetParent(target) '座標系を親のに
            e.Handled = True
        End Sub
    
        Private Sub Window_ManipulationDelta(sender As Object, e As ManipulationDeltaEventArgs)
            If target Is Nothing Then
                Return
            End If
    
            Dim parent As FrameworkElement = VisualTreeHelper.GetParent(target)
            Dim cloneMatrix As Matrix = Me.originalMatrix
    
            'オブジェクトの移動を行う。
            cloneMatrix.Translate(e.CumulativeManipulation.Translation.X, e.CumulativeManipulation.Translation.Y)
    
            'オブジェクトの拡大縮小を行う。
            Dim scale = Math.Max(e.CumulativeManipulation.Scale.X, e.CumulativeManipulation.Scale.Y)
    
            '拡縮範囲の制限
            Dim temp As Double = cloneMatrix.M11 * scale
            If temp < scaleMin Then
                scale = scaleMin / cloneMatrix.M11
            End If
            If scaleMax < temp Then
                scale = scaleMax / cloneMatrix.M11
            End If
            cloneMatrix.ScaleAt(scale, scale, e.ManipulationOrigin.X, e.ManipulationOrigin.Y)
            Debug.Print("TotalScale=" + cloneMatrix.M11.ToString())
    
            '親の座標に変換
            Dim ps(0 To 1) As Point
            ps(0) = New Point(0, 0)
            ps(1) = New Point(target.ActualWidth, target.ActualHeight)
            cloneMatrix.Transform(ps)
    
            'はみ出た部分を中に移動しなおし
            If parent.ActualWidth < ps(1).X Then
                cloneMatrix.Translate(parent.ActualWidth - ps(1).X, 0)
            ElseIf ps(0).X < 0 Then
                cloneMatrix.Translate(-ps(0).X, 0)
            End If
    
            If parent.ActualHeight < ps(1).Y Then
                cloneMatrix.Translate(0, parent.ActualHeight - ps(1).Y)
            ElseIf ps(0).Y < 0 Then
                cloneMatrix.Translate(0, -ps(0).Y)
            End If
    
            target.RenderTransform = New MatrixTransform(cloneMatrix)
        End Sub
    
        Private Sub Window_ManipulationCompleted(sender As Object, e As ManipulationCompletedEventArgs)
            If target Is Nothing Then
                Return
            End If
            target = Nothing
            If focusedCombo IsNot Nothing Then
                focusedCombo.IsDropDownOpen = True
            End If
            focusedCombo = Nothing
        End Sub
    End Class
    
    Class commonTextBox1
        Inherits TextBox
        Public Property CmbText As String
    End Class
    Class clsComboBoxInput
        Inherits ComboBox
    End Class



    個別に明示されていない限りgekkaがフォーラムに投稿したコードにはフォーラム使用条件に基づき「MICROSOFT LIMITED PUBLIC LICENSE」が適用されます。(かなり自由に使ってOK!)

    • 回答としてマーク WPFNN 2019年4月18日 8:26
    2019年4月17日 17:00
  • ご連絡が遅くなり、申し訳ありませんでした。

    記載していただいたソースコードを参考に実装してみたいと思います。

    ありがとうございました。

    2019年4月18日 8:26