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>
4

1 回答 1

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

于 2010-12-22T10:45:18.787 回答