WPF - 水平结合影像的ListView [英] WPF - bind images horizontally to ListView

查看:100
本文介绍了WPF - 水平结合影像的ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这里看到过类似的问题但继答案有没有解决这个同样的问题。的静止图像垂直列出。我从Netflix的结合的OData。

以下是XAML: -

 < Window.Resources>
          <的DataTemplate X:键=的ImageCell>
            < StackPanel的方向=横向>
                <图像来源={结合BoxArt.MediumUrl}WIDTH =200HEIGHT =200拉伸=填充工具提示={结合剧情简介}/>
            < / StackPanel的>
        < / DataTemplate中>
    < /Window.Resources> < ListView的保证金=21,40,26,9NAME =lvwTitles的ItemsSource ={结合}
   IsSynchronizedWithCurrentItem =真
 的SelectionMode =单的ItemTemplate ={StaticResource的的ImageCell}>
 < /&的ListView GT;

以下是背后的code: -

 列表<标题>标题= serviceAccessor.GetAllTitlesByGenre(cmbGenre.SelectedValue.ToString());
lvwTitles.ItemsSource =职称;


您使用的是放错了地方的StackPanel中。在DataTemplate中的StackPanel的只是创建包含一个单一的形象StackPanel中,以便在ListView中的每个项目。尝试将itemspanel ..是这样的:

 <&的ListView GT;
    < ListView.ItemsPanel>
        < ItemsPanelTemplate>
            < StackPanel的方向=横向/>
        < / ItemsPanelTemplate>
    < /ListView.ItemsPanel>
...
< /&的ListView GT;

I see a similar question here but following the answer there doesn't resolve this same issue. Images are still listed vertically. I am binding oData from NetFlix.

Following is the XAML :-

    <Window.Resources>
          <DataTemplate x:Key="ImageCell">
            <StackPanel Orientation="Horizontal">
                <Image Source="{Binding BoxArt.MediumUrl}" Width="200" Height="200" Stretch="Fill" ToolTip="{Binding Synopsis}"/>
            </StackPanel>
        </DataTemplate>
    </Window.Resources>

 <ListView Margin="21,40,26,9" Name="lvwTitles" ItemsSource="{Binding}" 
   IsSynchronizedWithCurrentItem="True" 
 SelectionMode="Single" ItemTemplate="{StaticResource ImageCell}">        
 </ListView>

Following is the code behind:-

List<Title> titles = serviceAccessor.GetAllTitlesByGenre(cmbGenre.SelectedValue.ToString());
lvwTitles.ItemsSource = titles;

解决方案

You are using the stackpanel in the wrong place. The stackpanel in the datatemplate just creates a stackpanel containing one single image, for each item in the listview. Try setting the itemspanel.. something like this:

<ListView>
    <ListView.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal" />
        </ItemsPanelTemplate>
    </ListView.ItemsPanel>
...
</ListView>

这篇关于WPF - 水平结合影像的ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆