C# 控件作为第二个控件的一部分时未填充所有可用空间
我有一个用户控件,它由一个显示一组图像的列表视图组成。这个列表视图工作得很好C# 控件作为第二个控件的一部分时未填充所有可用空间,c#,wpf,winforms,C#,Wpf,Winforms,我有一个用户控件,它由一个显示一组图像的列表视图组成。这个列表视图工作得很好 <UserControl x:Class="ItemViewer.WPF.CustomControls.ctrlImageViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/200
<UserControl x:Class="ItemViewer.WPF.CustomControls.ctrlImageViewer"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:ValueConverters="clr-namespace:ItemViewer.WPF.ValueConverters"
xmlns:WPFHelper="clr-namespace:ItemViewer.WPF"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:ItemViewer.WPF.CustomControls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<UserControl.Resources>
<ValueConverters:FilenameValueConverter x:Key="imageConverter" />
<ValueConverters:GroupNameConverter x:Key="groupNameConverter" />
</UserControl.Resources>
<UserControl.DataContext>
<local:ImageCollectionVM />
</UserControl.DataContext>
<Grid x:Name="MainGrid">
<!-- The list view containing the images, bound to the logos collection in the background -->
<ListView x:Name="ImagesListView"
Grid.Row="1"
Background="Transparent"
BorderThickness="0"
ItemsSource="{Binding ItemImages}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedIndex="{Binding SelectedIndex,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}"
TabIndex="2">
<!--
Use a wrap panel so that the images appear side by side instead of one in each row
We use a virtualising list view as there are enough images to slow down the performance
-->
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<!-- We use a virtualising panel as there are too many images to be loaded in adequate amount of time -->
<WPFHelper:VirtualizingWrapPanel />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<!-- Sets the template for the data to be displayed -->
<ListView.ItemTemplate>
<DataTemplate>
<Border Margin="2">
<!-- Set the style -->
<Border.Style>
<Style>
<Style.Triggers>
<Trigger Property="UIElement.IsMouseOver" Value="True">
<Setter Property="Border.BorderBrush" Value="LimeGreen" />
<Setter Property="Border.BorderThickness" Value="3" />
<Setter Property="Border.CornerRadius" Value="5" />
</Trigger>
<Trigger Property="UIElement.IsMouseOver" Value="False">
<Setter Property="Border.BorderBrush" Value="LightSkyBlue" />
<Setter Property="Border.BorderThickness" Value="2" />
<Setter Property="Border.CornerRadius" Value="2" />
</Trigger>
</Style.Triggers>
</Style>
</Border.Style>
<StackPanel Background="White">
<!-- Defines the actual image being displayed -->
<Image x:Name="ItemImageControl"
Width="80"
Height="150"
Margin="1"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Cursor="Hand"
Source="{Binding Converter={StaticResource imageConverter},
Mode=OneWay}" />
<TextBlock HorizontalAlignment="Center"
FontWeight="Bold"
Text="{Binding Converter={StaticResource groupNameConverter},
Mode=OneWay}" />
</StackPanel>
</Border>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</UserControl>
然后,我将其中三个控件放在第二个WPF用户控件上,每个控件都在扩展器中,用一个文本块显示一些信息
<UserControl x:Class="ItemViewer.WPF.CustomControls.ctrlImageCollection"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:CustomControls="clr-namespace:ItemViewer.WPF.CustomControls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="auto" />
<RowDefinition Height="*" />
<RowDefinition Height="auto" />
</Grid.RowDefinitions>
<Expander Grid.Row="0"
Margin="4">
<CustomControls:ctrlImageViewer x:Name="ImageViewer1" />
</Expander>
<Expander Grid.Row="1"
Margin="4">
<CustomControls:ctrlImageViewer x:Name="ImageViewer2" />
</Expander>
<Expander Grid.Row="2"
Margin="4">
<CustomControls:ctrlImageViewer x:Name="ImageViewer2" />
</Expander>
<StatusBar Grid.Row="4" Background="LightSkyBlue">
<TextBlock Name="txtReference" />
</StatusBar>
</Grid>
</UserControl>
然后,第二个控件将在Windows窗体项目中使用,并停靠在窗体的左侧
当我将图像添加到第一个usercontrols中的一个,而它是第二个usercontrols的一部分时,图像都在那里,但是listview没有展开
我需要将列表ImageViewer(第一个控件)展开以填充所有可用空间,但目前还没有
我想知道这是否可以归结为使用我从
有人能帮我吗?是否可以暂时将第三方包装换成实际的包装,以查看是否出现相同的问题?是的,包装面板自身调整了大小,因此这一定与虚拟化包装面板有关。