2010-12-22 34 views
1

我有一個擴展器,其中包含一個顯示圖像縮略圖的列表框。我希望根據列表框的大小和列表框的大小根據擴展器的寬度來調整圖像大小。當我展開擴展器時,我想要列表框和圖像也要調整大小。有誰知道我能做到這一點?在列表框中顯示圖像,使圖像根據父容器調整大小

<Expander 
      Style="{DynamicResource ExpanderStyle}" 
      Name="pictureExpander" 
      IsExpanded="True"     
      ExpandDirection="Left" 
      Collapsed="pictureExpander_Collapsed" 
      Expanded="pictureExpander_Expanded" 
      Grid.Column="4"> 
      <ListBox 
       Name="photoList" 
       ItemsSource="{Binding Source={StaticResource PhotoBin}}" 
       IsSynchronizedWithCurrentItem="True" 
       HorizontalAlignment="Stretch" 
       ScrollViewer.CanContentScroll="False"> 
       <ListBox.ItemContainerStyle> 
        <Style TargetType="{x:Type ListBoxItem}"> 
         <Style.Resources> 
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow" /> 
         </Style.Resources> 
         <Style.Triggers> 
          <Trigger Property="IsSelected" Value="True"> 
           <Setter Property="BorderBrush" Value="Black"/> 
           <Setter Property="BorderThickness" Value="5"/> 
          </Trigger> 
         </Style.Triggers> 
        </Style> 
       </ListBox.ItemContainerStyle> 
       <ListBox.ItemTemplate> 
        <DataTemplate> 
         <Image 
          Source="{Binding FileLocation}" 
          Margin="0,5" 
          HorizontalAlignment="Stretch" 
          MouseLeftButtonDown="DragImage" /> 
        </DataTemplate> 
       </ListBox.ItemTemplate> 
      </ListBox> 
     </Expander> 

回答

1

通過使用圖像上的 「拉伸」 屬性:

<Image 
    Source="{Binding FileLocation}" 
    Margin="0,5" 
    MouseLeftButtonDown="DragImage" 
    Stretch="Uniform" 
    StretchDirection="Both"/> 

您可以用價值發揮得到你想要的效果:

http://msdn.microsoft.com/en-en/library/system.windows.controls.image.stretch.aspx

http://msdn.microsoft.com/en-en/library/system.windows.controls.image.stretchdirection.aspx

http://msdn.microsoft.com/en-us/library/system.windows.media.stretch.aspx

http://msdn.microsoft.com/en-us/library/system.windows.controls.stretchdirection.aspx

+0

我能得到它,當我操縱擴展,但現在的問題是,當應用程序呈現正以自己的全尺寸顯示的圖像來調整。我怎麼得到它最初有一個約200像素的寬度? – MBU 2010-12-22 17:47:58

相關問題