WPF在Image控件中显示listview项

时间:2017-04-26 12:05:20

标签: wpf listview

我有一个Listview,旁边有一个Image控件。我为CollectionOfCapturedImages的ItemsSource设置了Listview

public ObservableCollection<BitmapImage> CollectionOfCapturedImages { get; } = new ObservableCollection<BitmapImage>();

<ListView x:Name="testListView" ItemsSource="{Binding CollectionOfCapturedImages}" MouseLeftButtonDown="testListView_MouseLeftButtonDown" Height="345"  Margin="567,10,10,0" VerticalAlignment="Top">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <UniformGrid Columns="1" HorizontalAlignment="Center" VerticalAlignment="Top"/>
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Vertical">
                        <Image Source="{Binding}" Height="150" Width="150"/>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

如何在Listview控件中显示所选BitmapImage项(Image)? 我试图添加MouseLeftButtonDown="testListView_MouseLeftButtonDown"

private void testListView_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            newlyAddedImage.Source = testListView.SelectedItem;
        }

我怎样才能使这个工作?

1 个答案:

答案 0 :(得分:1)

您是否尝试将Source的{​​{1}}属性绑定到Image的{​​{1}}属性?

SelectedItem