我对 ItemsContainerStyle 有一个奇怪的问题。我为 ItemsContainerStyle 定义了两种不同的样式:
<Style x:Key="LeftAligned">
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Left" />
</Style>
<Style x:Key="FullSelectionBox">
<Setter Property="FrameworkElement.HorizontalAlignment" Value="Stretch" />
</Style>
在运行时我更改样式:
LogViewer.ItemContainerStyle = (Style) FindResource ("FullSelectionBox");
或者
LogViewer.ItemContainerStyle = (Style) FindResource ("LeftAligned");
更改样式后,PreviewMouseLeftButtonUp、PreviewMouseRightButtonUp 或 PreviewMouseUp 事件不会以正确的方式触发。在大多数情况下,如果事件发生与否,它是俄罗斯轮盘赌。
任何想法为什么我的应用程序有这种奇怪的行为?