我有一个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;
}
我怎样才能使这个工作?
答案 0 :(得分:1)
您是否尝试将Source
的{{1}}属性绑定到Image
的{{1}}属性?
SelectedItem