Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to bind the ListView SelectedItem to an Image. Seems simple, but I don't know what I am doing wrong. Help Please :)


HTML
<Window x:Class="ListViewImageSelection.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="300" Width="400">

    <Window.Resources>
        <BitmapImage x:Key="bike"   UriSource="Images/bike.bmp"/>
        <BitmapImage x:Key="car"    UriSource="Images/car.bmp"/>
        <BitmapImage x:Key="flower" UriSource="Images/flower.bmp"/>
    </Window.Resources>


    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="150"/>
        </Grid.ColumnDefinitions>

    

        <ListView Name="MyListView" Grid.Column="1" VerticalAlignment="bottom"  HorizontalAlignment="Center" ScrollViewer.PanningMode="VerticalOnly">
            <Image Source="{StaticResource bike}" Width="110" />
            <Image Source="{StaticResource car}" Width="110" />
            <Image Source="{StaticResource flower}" Width="110" />
        </ListView>

        <Image Grid.Column="0" Stretch="Uniform"  Source="{Binding ElementName=MyListView, Path=SelectedItem.ImageUri}"/>


    </Grid>
</Window>
Posted

1 solution

Set the Image binding path to the SelectedItem.Source

C#
<image grid.column="0" source="{Binding ElementName=MyListView, Path=SelectedItem.Source}" />

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900