【发布时间】:2011-08-01 20:48:59
【问题描述】:
我的应用中有 2 个列表框使用
<Window.Resources>
<ItemsPanelTemplate x:Key="WrapPanelTemplate">
<WrapPanel Width="290"/>
</ItemsPanelTemplate>
<DataTemplate x:Key="ButtonItemTemplate">
<Button Content="{Binding Path=Name}" Width="120" Margin="3,2,3,2" />
</DataTemplate>
</Window.Resources>
一切看起来都很棒,但是当我尝试单击它们时,它们并没有选择新项目。我已将 SelectedItem 绑定到我的视图模型上的一个属性,但是每当我选择一个新项目时,set 方法都不会发生。我有一个常规的列表框,它以相同的方式连接并且可以正常工作。下面是自定义列表框的实现:
<ListBox Height="284" HorizontalAlignment="Left" x:Name="faveProgramsButtons"
ItemsSource="{Binding Path=FavoriteAppList}"
SelectedItem="{Binding Path=FavoriteAppList_SelectedApp}" VerticalAlignment="Top"
Width="281" ItemsPanel="{StaticResource WrapPanelTemplate}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
ItemTemplate="{StaticResource ButtonItemTemplate}">
</ListBox>
谢谢!
【问题讨论】: