2013-03-25 64 views
0

以適合給定的高度和寬度WPF窗口我需要增加我的圖片OnMouseOver,其被放置在一個StackPanel與取向爲水平的HeightWidth使得圖像跨越我的整個面板與我的WPF window中給定的尺寸,這是無法實現的。請讓我知道如果我錯過了我的xaml屬性中的任何數學或我的方法有任何問題。 在此先感謝。在鼠標懸停不調整大小圖像使用XAML

以下是我的xaml,後來是我的輸出圖像。

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="245"/> 
    </Grid.RowDefinitions> 

    <StackPanel x:Name="TitleSlidesPanel" Grid.Row="0" 
       Orientation="Horizontal"> 
     <StackPanel Orientation="Vertical" 
      Height="245" 
       Width="400" > 

      <Image x:Name="img1" VerticalAlignment="Top" 
       HorizontalAlignment="Left" 
       RenderOptions.BitmapScalingMode="HighQuality" 
       Style="{StaticResource imageStyle}" 
       MouseDown="Img1_OnMouseDown" 
       MouseUp="Img1_OnMouseUp"> 
      </Image> 
      <CheckBox x:Name="Chkbox1" 
       Content="Image1" 
         Width="100" 
         HorizontalContentAlignment="Left" 
       HorizontalAlignment="Left" 
       VerticalContentAlignment="Center" 
       FontSize="12" 
       Margin="0,5,0,0" 
       Foreground="Black" 
       Height="20"> 
      </CheckBox> 
     </StackPanel> 
     <StackPanel Orientation="Vertical" 
        Height="245" 
       Width="400" 
        Margin="-400,0,0,0" > 

      <Image x:Name="Img2" VerticalAlignment="Top" 
       HorizontalAlignment="Right" 
       RenderOptions.BitmapScalingMode="HighQuality" 
       Style="{StaticResource imageStyle}" 
       MouseDown="Img2_OnMouseDown" 
       MouseUp="Img2_OnMouseUp" > 
      </Image> 
      <CheckBox x:Name="Chkbox2" 
       Content="Image2" 
       FontSize="12" 
       Margin="0,5,135,0" 
       HorizontalContentAlignment="Right" 
       HorizontalAlignment="Right" 
       VerticalContentAlignment="Center" 
       Foreground="Black" 
       Height="20"> 
      </CheckBox> 
     </StackPanel> 
    </StackPanel> 
</Grid> 


<Style x:Key="imageStyle" TargetType="{x:Type Image}"> 
    <Setter Property="Height" Value="100" /> 
    <Setter Property="Width" Value="200" /> 
    <Style.Triggers> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Height" Value="245" /> 
      <Setter Property="Width" Value="400" /> 
     </Trigger> 
    </Style.Triggers> 
</Style> 

DefaultView

OnMouseOverFirstImage

OnMouseOverSecondImage

回答

0

嘗試把你的風格無論是在StackPanel中或電網的資源。

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="245"/> 
    </Grid.RowDefinitions> 
<Grid.Resources> 
    <Style x:Key="imageStyle" TargetType="{x:Type Image}"> 
     <Setter Property="Height" Value="100" /> 
     <Setter Property="Width" Value="200" /> 
     <Style.Triggers> 
      <Trigger Property="IsMouseOver" Value="True"> 
       <Setter Property="Height" Value="245" /> 
       <Setter Property="Width" Value="400" /> 
      </Trigger> 
     </Style.Triggers> 
    </Style> 
</Grid.Resources> 
    <StackPanel x:Name="TitleSlidesPanel" Grid.Row="0" 
       Orientation="Horizontal"> 
     <StackPanel Orientation="Vertical" 
      Height="245" 
       Width="400" > 

      <Image x:Name="img1" VerticalAlignment="Top" 
       HorizontalAlignment="Left" 
       RenderOptions.BitmapScalingMode="HighQuality" 
       Style="{StaticResource imageStyle}" 
       MouseDown="Img1_OnMouseDown" 
       MouseUp="Img1_OnMouseUp"> 
      </Image> 
      <CheckBox x:Name="Chkbox1" 
       Content="Image1" 
         Width="100" 
         HorizontalContentAlignment="Left" 
       HorizontalAlignment="Left" 
       VerticalContentAlignment="Center" 
       FontSize="12" 
       Margin="0,5,0,0" 
       Foreground="Black" 
       Height="20"> 
      </CheckBox> 
     </StackPanel> 
     <StackPanel Orientation="Vertical" 
        Height="245" 
       Width="400" 
        Margin="-400,0,0,0" > 

      <Image x:Name="Img2" VerticalAlignment="Top" 
       HorizontalAlignment="Right" 
       RenderOptions.BitmapScalingMode="HighQuality" 
       Style="{StaticResource imageStyle}" 
       MouseDown="Img2_OnMouseDown" 
       MouseUp="Img2_OnMouseUp" > 
      </Image> 
      <CheckBox x:Name="Chkbox2" 
       Content="Image2" 
       FontSize="12" 
       Margin="0,5,135,0" 
       HorizontalContentAlignment="Right" 
       HorizontalAlignment="Right" 
       VerticalContentAlignment="Center" 
       Foreground="Black" 
       Height="20"> 
      </CheckBox> 
     </StackPanel> 
    </StackPanel> 
</Grid> 
+0

嘿,謝謝你的迴應。但是,這並沒有奏效。我試過了。 – user1105705 2013-03-25 08:16:44