0

I have a Listview and next to it an Image control. I have set CollectionOfCapturedImages for my Listview's ItemsSource.

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>

How could I display selected Listview item (BitmapImage) in my Image control? I have tried to add MouseLeftButtonDown="testListView_MouseLeftButtonDown"

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

how can I get this working?

1 Answer 1

1

Did you try to just bind the Source property of the Image to the SelectedItem property of the ListView?

<Image x:Name="newlyAddedImage" Source="{Binding SelectedItem, ElementName=testListView}" />
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.