如何将ListView SelectedItem与图像进行比较 [英] How Do I BInd ListView SelectedItem to Image
问题描述
我正在尝试将ListView SelectedItem绑定到Image。看似简单,但我不知道我做错了什么。请帮助:)
< 窗口 x:Class = ListViewImageSelection.MainWindow
xmlns = http://schemas.microsoft.com/winfx/2006/xaml/presentation
xmlns:x = http://schemas.microsoft .com / winfx / 2006 / xaml
< span class =code-attribute> 标题 = MainWindow 高度 = 300 宽度 = 400 >
< Window.Resources >
< BitmapImage x:Key = bike UriSource = 图片/bike.bmp\" / >
< BitmapImage x:键 = car UriSource = Images / car.bmp / >
< BitmapImage x:Key = flower UriSource = 图片s / flower.bmp / >
< / Window.Resources >
< 网格 >
< Grid.ColumnDefinitions >
< ColumnDefinition / >
< ColumnDefinition 宽度 = 150 / >
< / Grid.ColumnDefinitions >
< ListView 名称 = MyListView Grid.Column = 1 VerticalAlignment = bottom HorizontalAlignment = 中心 ScrollViewer.PanningMode = VerticalOnly >
< 图像 来源 = {StaticResource bike} 宽度 = 110 / >
< 图像 来源 = {StaticResource car} 宽度 = 110 / >
< 图片 来源 = {StaticResource flower} 宽度 = 110 / >
< / ListView < span class =code-keyword>>
< Image Grid.Column = 0 拉伸 = 统一 来源 = {Binding ElementName = MyListView,Path = SelectedItem.ImageUri} / > ;
< / Grid < span class =code-keyword>>
< / Window >
将 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 :) Set the 这篇关于如何将ListView SelectedItem与图像进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! Image
绑定路径设置为 SelectedItem.Source
< image grid.column = 0来源= {Binding ElementName = MyListView,Path = SelectedItem.Source} />
<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>
Image
binding path to the SelectedItem.Source
<image grid.column="0" source="{Binding ElementName=MyListView, Path=SelectedItem.Source}" />