Mouse scroll not working in a scroll viewer with a wpf datagrid and additional UI elements

前端 未结 10 1421
醉话见心
醉话见心 2021-02-03 18:41

I am trying to figure out how to get the mouse scroll working on a wpf window with a scrollviewer and a datagrid within it. The WPF and C# code is below



        
10条回答
  •  粉色の甜心
    2021-02-03 18:46

    Guys I`ve seen most of the solution posted over here and fundamentally all of them are right, but I think there is an easiest and more elegant syntax that we could apply.

    Assuming that we don't need to scroll with our data grid and instead we would like to scroll with our MainWindow

    fallowing "Dave" and "Vladim Tofan" answer

    Private Void Scrlll(Object sebder, MouseWheelEventArgs e)
    {
       var windows = (Window.GetWindow(this) as MainWindow).MainScroll;
       windows.ScrollToVerticalOffset(windows.VerticalOffset - e.Delta);
    }
    

    Sorry, for bad english.

提交回复
热议问题