わかりましたので、ここにあなたの解決策があります...私は再び単純なトリガーを使用しました。
<Control>
<Control.Template>
<ControlTemplate>
<Canvas>
<Grid x:Name="HouseBody" Height="153" Width="350" HorizontalAlignment="Left" VerticalAlignment="Bottom" Canvas.Left="78" Canvas.Top="159">
<Rectangle Height="Auto" Fill="Blue" x:Name="body" Stroke="Black" Width="Auto"/>
<Rectangle Height="Auto" Fill="Blue" x:Name="window" Stroke="Black" Width="89" HorizontalAlignment="Left" Margin="25,17,0,54"/>
<Rectangle Fill="Blue" Height="Auto" x:Name="door" Stroke="Black" Width="Auto" Margin="235.5,17,25.5,0" HorizontalAlignment="Stretch"/>
</Grid>
<Grid x:Name="HouseRoof" Height="131.5" Width="350" HorizontalAlignment="Left" VerticalAlignment="Bottom" Canvas.Left="77" Canvas.Top="27.5">
<Rectangle Height="Auto" Fill="Blue" x:Name="chimney" Stroke="Black" Width="40" HorizontalAlignment="Stretch" Margin="44.066,22.965,265.934,8" />
<Path x:Name="path" Data="M74.752528,159.37536 L429.11068,159.37578 242,26.5 z" Fill="Blue" Height="Auto" Stretch="Fill" Stroke="Black" Width="Auto" Margin="0.25,0,-2.589,-0.865"/>
</Grid>
</Canvas>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="body" Property="Fill" Value="Red" />
<Setter TargetName="window" Property="Fill" Value="Red" />
<Setter TargetName="door" Property="Fill" Value="Red" />
<Setter Property="Fill" TargetName="path" Value="Red"/>
<Setter Property="Fill" TargetName="chimney" Value="Red"/>
<Setter Property="Width" TargetName="HouseBody" Value="395"/>
<Setter Property="Width" TargetName="HouseRoof" Value="395"/>
</Trigger>
<!--<Trigger Property="IsMouseOver" Value="False">
<Setter TargetName="body" Property="Fill" Value="Green" />
<Setter TargetName="window" Property="Fill" Value="Green" />
<Setter TargetName="door" Property="Fill" Value="Green" />
<Setter TargetName="triangle" Property="Fill" Value="Green" />
</Trigger>-->
</ControlTemplate.Triggers>
</ControlTemplate>
</Control.Template>
</Control>
大きな変更点は、ポリゴンをパスに置き換えたことだけです。私が助けてくれることを願っています。StoryBoards でも同じことができます。もちろん、codeBehind と C# を使用して、オブジェクトを名前付きグリッドにグループ化すると、はるかに簡単になります。グリッドの幅とその完了のみを設定します。
次のようになります。
XAML:
<Grid>
<Canvas MouseLeftButtonDown="Canvas_MouseLeftButtonDown" MouseLeftButtonUp="Canvas_MouseLeftButtonUp">
<Grid x:Name="HouseBody" Height="153" Width="350" HorizontalAlignment="Left" VerticalAlignment="Bottom" Canvas.Left="78" Canvas.Top="159">
<Rectangle Height="Auto" Fill="Blue" x:Name="body" Stroke="Black" Width="Auto"/>
<Rectangle Height="Auto" Fill="Blue" x:Name="window" Stroke="Black" Width="89" HorizontalAlignment="Left" Margin="25,17,0,54"/>
<Rectangle Fill="Blue" Height="Auto" x:Name="door" Stroke="Black" Width="Auto" Margin="235.5,17,25.5,0" HorizontalAlignment="Stretch"/>
</Grid>
<Grid x:Name="HouseRoof" Height="131.5" Width="350" HorizontalAlignment="Left" VerticalAlignment="Bottom" Canvas.Left="77" Canvas.Top="27.5">
<Rectangle Height="Auto" Fill="Blue" x:Name="chimney" Stroke="Black" Width="40" HorizontalAlignment="Stretch" Margin="44.066,22.965,265.934,8" />
<Path x:Name="path" Data="M74.752528,159.37536 L429.11068,159.37578 242,26.5 z" Fill="Blue" Height="Auto" Stretch="Fill" Stroke="Black" Width="Auto" Margin="0.25,0,-2.589,-0.865"/>
</Grid>
</Canvas>
</Grid>
コードビハインド:
private void Canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
HouseBody.Width = 400;
HouseRoof.Width = 400;
}
private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
{
HouseBody.Width = 350;
HouseRoof.Width = 350;
}