私は以下のようにusercontrolを作成しました。 以下のコードに私のXAMLコードを参照してください。グリッド列*行(4 * 5)がwpfでキャンバスにとどまるとき、グリッドにドラッグデルタを実装するには
<Border ClipToBounds="True" BorderThickness="2" BorderBrush="DeepPink" Width="200" Height="150" x:Name="TempMaxEntityBorder">
<Canvas x:Name="TempMaxEntityCanvas" Background="LightPink" Focusable="True" AllowDrop="True" Tag="MatrixEntityCanvas" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid x:Name="GridLayout" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
<Grid.RowDefinitions >
<RowDefinition Height="Auto" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="Entity" TextAlignment="Center" Grid.Row="0" Grid.Column="0" FontSize="16" VerticalAlignment="Center" HorizontalAlignment="Center" Width="200"></TextBlock>
<Line Margin="0,5,0,0" Grid.Row="1" Grid.Column="0" Stroke="DeepPink" StrokeThickness="2" X2="{Binding Path=ActualWidth, RelativeSource={RelativeSource Self}}" VerticalAlignment="Top" />
<Grid x:Name="ChildGridLayout" Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<Grid.ColumnDefinitions >
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Rectangle Grid.Row="0" Grid.Column="0" Width="20" Height="25" StrokeThickness="2" Stroke="DeepPink" ></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="0" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="1" Grid.Column="0" Text="a" Padding="22,5"/>
<Rectangle Grid.Row="2" Grid.Column="0" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="2" Grid.Column="0" Text="a" Padding="22,0"/>
<Rectangle Grid.Row="3" Grid.Column="0" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="3" Grid.Column="0" Text="a" Padding="22,0"/>
<Rectangle Grid.Row="4" Grid.Column="0" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="4" Grid.Column="0" Text="a" Padding="22,0"/>
<Rectangle Grid.Row="0" Grid.Column="1" Width="20" Height="25" StrokeThickness="2" Stroke="DeepPink"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="1" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="1" Grid.Column="1" Text="b" Padding="22,0"/>
<Rectangle Grid.Row="2" Grid.Column="1" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="2" Grid.Column="1" Text="b" Padding="22,0"/>
<Rectangle Grid.Row="3" Grid.Column="1" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="3" Grid.Column="1" Text="b" Padding="22,0"/>
<Rectangle Grid.Row="4" Grid.Column="1" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="4" Grid.Column="1" Text="b" Padding="22,0"/>
<Rectangle Grid.Row="0" Grid.Column="2" Width="20" Height="25" StrokeThickness="2" Stroke="DeepPink"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="2" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="1" Grid.Column="2" Text="c" Padding="22,0"/>
<Rectangle Grid.Row="2" Grid.Column="2" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="2" Grid.Column="2" Text="c" Padding="22,0"/>
<Rectangle Grid.Row="3" Grid.Column="2" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="3" Grid.Column="2" Text="c" Padding="22,0"/>
<Rectangle Grid.Row="4" Grid.Column="2" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="4" Grid.Column="2" Text="c" Padding="22,0"/>
<Rectangle Grid.Row="0" Grid.Column="3" Width="20" Height="25" StrokeThickness="2" Stroke="DeepPink"></Rectangle>
<Rectangle Grid.Row="1" Grid.Column="3" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="1" Grid.Column="3" Text="d" Padding="22,0"/>
<Rectangle Grid.Row="2" Grid.Column="3" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="2" Grid.Column="3" Text="d" Padding="22,0"/>
<Rectangle Grid.Row="3" Grid.Column="3" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="3" Grid.Column="3" Text="d" Padding="22,0"/>
<Rectangle Grid.Row="4" Grid.Column="3" Width="20" Height="20" StrokeThickness="1" Stroke="DeepPink" RadiusX="10" RadiusY="10" Fill="Transparent"></Rectangle>
<TextBlock Grid.Row="4" Grid.Column="3" Text="d" Padding="22,0"/>
</Grid>
</Grid>
</Canvas>
</Border>
は、私はC#のファイルと、この仕事は良いの私の親指のコードを記述します。 しかし、親指でキャンバスにdragDeltaを使用すると、このキャンバスはサムを使用してサイズ変更されますが、グリッドはサイズ変更されません。グリッドは同じ位置にとどまります。
ありがとうございます。だから、この親キャンバスにグリッドをバインドする方法。
キャンバスの実際のサイズに結合すること: '<グリッドは、x:NAME = "GridLayoutの" 高さ= "{のElementName = TempMaxEntityCanvas結合、パス= ActualHeight}" 幅=" {、のElementName = TempMaxEntityCanvas結合Path = ActualWidth} "> ' – kennyzx