至于我的问题(标题),我已经可以将列表框中的选定项目绑定到我的uniformGrid。 但是即使我已经选择了许多项目,UniformGrid 也只显示 1 个项目。
你能告诉我怎么做吗?
或者 是否可以用选定的 ListBox 项目填充 UniformGrid?
或者 还有哪些其他选项可以传输(绑定)并从我的列表框中显示我的选定项目?
或者 ,如果您有类似的示例,我将直接浏览代码。
确切地说,我的 ListBox 项目是图像,但不需要只是图像。我只想知道如何将所选项目绑定到 Grid 或任何将显示我的 ListBox 所选项目的东西。
谢谢你
XAML:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"
x:Class="SampleBinding.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<Window.Resources>
<DataTemplate x:Key="ItemTemplate">
<StackPanel>
<Image Source="{Binding myImages}" HorizontalAlignment="Left" Height="64" Width="64"/>
</StackPanel>
</DataTemplate>
</Window.Resources>
<Grid x:Name="LayoutRoot" DataContext="{Binding Source={StaticResource SampleDataSource}}">
<ListBox x:Name="listBox" HorizontalAlignment="Left" ItemTemplate="{DynamicResource ItemTemplate}" ItemsSource="{Binding Collection}" Margin="19,40,0,102" Width="200" SelectionMode="Multiple"/>
<UniformGrid x:Name="uGrid" DataContext="{Binding SelectedItem, ElementName=listBox}" Margin="273,40,78,132" d:DataContext="{Binding Collection[0]}" Grid.Row="2" Grid.Column="2">
<Image x:Name="imageItem" Source="{Binding myImages}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="100" Height="100"/>
</UniformGrid>
</Grid>