0
我有以下代碼列出列表框中的圖像。目前我有一個在IsMouseOver上顯示彈出窗口的鼠標懸停事件。我試圖找出如何將其更改爲IsSelected,但在當前上下文中不存在。有沒有辦法改變綁定,以便在選擇項目時打開彈出窗口?我試圖從代碼隱藏(SelectionChanged)做到這一點,但我無法定位彈出窗口。當列表框中的項目IsSelected時打開彈出框
<ListBox ItemContainerStyle="{StaticResource Fisk}" x:Name="listy" ItemsSource="{Binding Images}" Margin="40,0,0,0" Grid.Row="1" Grid.Column="1" Background="{x:Null}" BorderBrush="{x:Null}" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" KeyDown="listy_KeyDown" Loaded="listy_Loaded" SelectionChanged="listy_SelectionChanged">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<vwp:VirtualizingWrapPanel />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel x:Name="item">
<Image Width="250" ToolTipService.Placement="Center">
<Image.Source>
<BitmapImage UriSource="{Binding Path=., Mode=OneWay,UpdateSourceTrigger=Explicit}" CreateOptions="DelayCreation" CacheOption="None" />
</Image.Source>
</Image>
<Popup IsOpen="{Binding ElementName=item,Path=IsMouseOver, Mode=OneWay}" Placement="Center">
<Border BorderBrush="Black" BorderThickness="4">
<Image Width="280" ToolTipService.Placement="Center">
<Image.Source>
<BitmapImage UriSource="{Binding Path=., Mode=OneWay,UpdateSourceTrigger=Explicit}" CreateOptions="DelayCreation" CacheOption="None" />
</Image.Source>
</Image>
</Border>
</Popup>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
這似乎同時可見視圖內的工作,但如果我向下滾動,它應該加載更多的圖像,我得到以下異常: mscorlib.dll 中發生未處理的「System.InvalidOperationException」類型的異常其他信息:集合已被修改;枚舉操作可能不會執行。 – NeoID 2014-09-20 08:45:05
@NeoID您剛剛提到的錯誤與答案無關。好像你可能需要查看'vwp:VirtualizingWrapPanel'的實現。 – pushpraj 2014-09-20 08:52:58
@pushpraj好的,謝謝。我會研究它。 :) – NeoID 2014-09-20 09:00:11