2014-12-29 98 views
0

我正在一个WPF应用程序有一个ListView与几个图像源加载到它。如何绑定选定的图像,以便将其显示在网格中包含的较大查看区域中?绑定ListView SelectedItem

在此先感谢!

这里是我一起工作的代码:

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

+0

@Joe我想你的建议,但不能让它开始工作。我发布了我的代码,你可以看一下吗? – ScanMan

回答

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

工作完美!谢谢:) – ScanMan

+0

@ScanMan高兴听到所以请标记为已回答。我以为你将它绑定到你的对象ImageUri属性 –