绑定ListView SelectedItem

时间:2014-12-29 18:46:12

标签: wpf xaml

我正在开发一个WPF应用程序,它有一个ListView,其中加载了几个Image源。如何绑定所选图像,使其显示在网格中包含的较大查看区域中?

提前致谢!

以下是我正在使用的代码:

    <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>

1 个答案:

答案 0 :(得分:0)

<Image Source="{Binding ElementName=MyListView, Path=SelectedItem.ImageUri}"/>