none
VirtualizingStackPanel使用 <i:EventTrigger>在x64下时报错 RRS feed

  • 问题

  •  

    1.源码

    1. <ListBox.ItemsPanel>
                      <ItemsPanelTemplate >
                          <VirtualizingStackPanel  Orientation="Horizontal" IsItemsHost="True">
                              <i:Interaction.Triggers>
                                  <i:EventTrigger  EventName="MouseWheel">
                                      <ei:CallMethodAction   MethodName="VirtualizingStackPanel_MouseWheel"  TargetObject="           {Binding}"/>
                                  </i:EventTrigger>
                              </i:Interaction.Triggers>
                          </VirtualizingStackPanel>
                      </ItemsPanelTemplate>
                  </ListBox.ItemsPanel>
    2. 问题说明:在x86下不报错,在x64下面报错
    3. 错误如下:集合属性“System.Windows.Controls.VirtualizingStackPanel”.“Triggers”为 null。
    4. 请问如何解决?

    2018年9月12日 9:13

全部回复

  • Hello,

    根据你的描述, 你是想设置ListBox.Itempanel模板为VirtualizingStackpanel, 然后想在后台绑定ListBox的滚轮事件,但是根据我的测试, ListBox的MouseWheel的事件被Scrollviewer拦截, 你可以使用PreviewMouseWheel事件来解决。

    <ListBox Height="300" ItemsSource="{Binding interactions}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Width="100" Text="The name is:" />
                                <TextBlock Width="100" Text="{Binding Name}" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Width="100" Text="The Age is:" />
                                <TextBlock Width="100" Text="{Binding Age}" />
                            </StackPanel>
                        </StackPanel>
                    </DataTemplate>
                </ListBox.ItemTemplate>
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="PreviewMouseWheel">
                        <ei:CallMethodAction MethodName="mousewheel" TargetObject="{Binding}" />
                    </i:EventTrigger>
                </i:Interaction.Triggers>
                <ListBox.ItemsPanel>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel IsItemsHost="True" Orientation="Horizontal" />
                    </ItemsPanelTemplate>
                </ListBox.ItemsPanel>
    
            </ListBox>

    Model:

     public class interactiontest
        {
            public string Name { get; set; }
            public int Age { get; set; }
        }

    ViewModel:

      public class viewmodeltest
        {
            public ObservableCollection<interactiontest> interactions { get; set; }
           
            public viewmodeltest()
            {
                interactions = new ObservableCollection<interactiontest>()
                {
                    new interactiontest(){Name="cherry",Age=12},
                    new interactiontest(){Name="cherry1",Age=12},
                    new interactiontest(){Name="cherry2",Age=12},
                    new interactiontest(){Name="cherry3",Age=12},
                    new interactiontest(){Name="cherry4",Age=12},
                    new interactiontest(){Name="cherry",Age=12},
                    new interactiontest(){Name="cherry1",Age=12},
                    new interactiontest(){Name="cherry2",Age=12},
                    new interactiontest(){Name="cherry3",Age=12},
                    new interactiontest(){Name="cherry4",Age=12},
                    new interactiontest(){Name="cherry",Age=12},
                    new interactiontest(){Name="cherry1",Age=12},
                    new interactiontest(){Name="cherry2",Age=12},
                    new interactiontest(){Name="cherry3",Age=12},
                    new interactiontest(){Name="cherry4",Age=12},
                    new interactiontest(){Name="cherry",Age=12},
                    new interactiontest(){Name="cherry1",Age=12},
                    new interactiontest(){Name="cherry2",Age=12},
                    new interactiontest(){Name="cherry3",Age=12},
                    new interactiontest(){Name="cherry4",Age=12}
    
                };
            }
    
            public void mousewheel(object sender, MouseWheelEventArgs e)
            {
                Console.WriteLine("OK");
            }
        }
     public partial class Window13 : Window
        {
           
            public Window13()
            {
                InitializeComponent();
                this.DataContext = new viewmodeltest();
            }         
        }

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    2018年9月20日 6:31
  • 谢谢你会的回答!

    我的这个问题不是这个事件没有执行,而是事件可以工作但是界面不能预览效果。

    2018年10月12日 6:42
  • 界面显示这个错误:集合属性“System.Windows.Controls.VirtualizingStackPanel”.“Triggers”为 null。
    2018年10月12日 6:43