对象之间的 WPF 事件处理
我对 C#/WPF 非常陌生,有 Obj-c 背景。我不太确定这在面向对象设计方面是如何工作的,以及不同的类如何看待彼此。
所以我有一个大视图(MainView),它有一些自定义绘图和底部的数据网格(数据网格位于其单独的 xaml 中,后面有 .cs 文件)。有一个自定义对象被添加到图中,当您拖动它时,数据网格会更新(通过使用 dataGrid.ScrollIntoView)。 ScrollIntoView 的代码位于 Datagrid 的 xaml.cs 文件中。
对我来说,这是有道理的,因为 MainView 拥有所有组件并“看到”所有对象,因此当调用 DragWindow 的事件处理程序时,MainView 会请求 DataGrid,并调用其方法来更新其列位置。 (这是我的理解,如有错误欢迎指正)。
现在我也想走另一条路。这样,如果我水平更新滚动条,那么 MainView 中的拖动窗口也会更新。这对我来说没有多大意义。我可以在数据网格的 xaml.cs 中创建一个事件处理程序。但它在MainView 中看不到dragWindow,对吧?所以我不太确定如何开始实现这个功能。任何帮助总是值得赞赏。谢谢!
I'm pretty new to C#/WPF, coming from Obj-c background. I'm not really sure how this works in terms of object oriented design, and how different classes see each other.
So I have a large view (MainView) that has some custom plots and a datagrid on the bottom (Datagrid is in its separate xaml and has .cs file behind it). There is a custom object that gets added to the plots that when you drag it, the datagrid gets updated (by using dataGrid.ScrollIntoView). The code for the ScrollIntoView is in the xaml.cs file of the Datagrid.
To me this makes sense since the MainView has all the components and "sees" all the objects, so when the event handler of the dragWindow gets called, then the MainView asks for the DataGrid, and calls its method to update its column position. (This is the way I understand it, please feel free to correct me if I'm wrong).
Now I want to go the other way as well. So that if I update the scrollbar horizontally, then the dragwindow in the MainView will get updated. This does not make as much sense to me. I can create an event handler in the xaml.cs of the datagrid. But it does not see the dragWindow in the MainView right? So I'm not quite sure how to start implementing this functionality. Any help is always appreciated. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的网格控件应该公开一个事件来通知任何使用者(在本例中为
MainView
)滚动已发生。然后,
MainView
可以在设计器或代码中将处理程序附加到此事件:Your grid control should expose an event to notify any consumers (
MainView
in this case) that scrolling has taken place.MainView
can then attach a handler to this event in the designer or in the code: