Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby-on-rails-4/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 缩放图像以将所有图像放入水平对齐的列表框中_C#_Wpf_Listview - Fatal编程技术网

C# 缩放图像以将所有图像放入水平对齐的列表框中

C# 缩放图像以将所有图像放入水平对齐的列表框中,c#,wpf,listview,C#,Wpf,Listview,我有一个绑定到枚举的水平列表框,其中包含一个EnumToImageSource转换器,需要列表框/视图来获取selectedItem 我需要在列表框中的图像,以缩小其宽度,使所有可见并排没有水平滚动条出现,即使在调整窗口大小 中的解决方案仅适用于正常的垂直列表视图。我想归档的东西能做到这一点吗 <ListBox HorizontalContentAlignment="Stretch" ScrollViewer.HorizontalScro

我有一个绑定到枚举的水平列表框,其中包含一个EnumToImageSource转换器,需要列表框/视图来获取selectedItem

我需要在列表框中的图像,以缩小其宽度,使所有可见并排没有水平滚动条出现,即使在调整窗口大小

中的解决方案仅适用于正常的垂直列表视图。我想归档的东西能做到这一点吗

<ListBox HorizontalContentAlignment="Stretch" 
                         ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                         ItemsSource="{Binding Source={StaticResource shoeValuesProvider}}">
                    <ListBox.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal"/>
                        </ItemsPanelTemplate>
                    </ListBox.ItemsPanel>

                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Image Source="{Binding Converter={StaticResource ShoeToImageConverter}}"/>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>

多亏了Sinatr的评论,我找到了一个解决方案,它确实使用了一个定义了一行的
UniformGrid
,并设置了祖先ScrollContentPresenter的宽度,如前所述:


多亏了Sinatr的评论,我找到了一个解决方案,它确实使用了一个定义了一行的
UniformGrid
,并设置了祖先ScrollContentPresenter的宽度,如前所述:



您是否尝试过
UniformGrid
作为
ItemsPanelTemplate
?您是否使用
列表框
选择编辑项
?我看不到绑定,也许你根本不需要
列表框
?编辑我的问题,我确实用它来获得
SelectedItem
-
Uniformgrid
将图像包装在新行上,而不进行缩放down@Sinatr我发布的答案有效,但当选择最后一幅图像时,视图向左滚动几个像素,我怎样才能解决这个问题?似乎在某个地方有一个消耗了几个像素的边界,请提出一个新的问题。不要忘记添加屏幕截图和相应的代码。这是。您是否尝试过使用
UniformGrid
作为
ItemsPanelTemplate
?您是否使用
列表框
选择编辑项
?我看不到绑定,也许你根本不需要
列表框
?编辑我的问题,我确实用它来获得
SelectedItem
-
Uniformgrid
将图像包装在新行上,而不进行缩放down@Sinatr我发布的答案有效,但当选择最后一幅图像时,视图向左滚动几个像素,我怎样才能解决这个问题?似乎在某个地方有一个消耗了几个像素的边界,请提出一个新的问题。不要忘记添加屏幕截图和相应的代码。这是。
<StackPanel x:Name="ReferenceStackPanel">
            <ListBox HorizontalContentAlignment="Stretch" 
                         ScrollViewer.HorizontalScrollBarVisibility="Hidden" 
                         SelectedItem="{Binding ShoeModel}" 
                         ItemsSource="{Binding Source={StaticResource shoeValuesProvider}}">
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <UniformGrid  Margin="0" Rows="1" Width="{Binding ActualWidth,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ScrollContentPresenter}}}"></UniformGrid>
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Image Source="{Binding Converter={StaticResource ShoeToImageConverter}}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </StackPanel>