当我单击单元格中的特定WPF网格单元格/控件时,如何触发事件 [英] How do I trigger an event when I click into a specific WPF grid cell / control in the cell

查看:355
本文介绍了当我单击单元格中的特定WPF网格单元格/控件时,如何触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WPF窗口中有一个页面。在这个页面中,我以程序方式(在方法的另一个类中)创建一个动态网格,我在其中实时添加行,并在启动之前从配置文件。



现在我也想删除行,但为此,当我点击第一列中每行中的删除位图图像时,我需要发生一些事情。但我不知道如何定位它,或者如何创建一个鼠标点击事件,我可以绑定到我的,而不是在XAML创建的网格中。



这是一个我的页面和网格的图像:

https://ibb.co/npJgoo



我尝试了什么:



我在网上搜索但因为我对c#很新,我发现没什么太复杂了我能够解决问题

I have a page in a WPF window. And in this page i programmically (in another class for methods) create a dynamic grid into which i add rows in realtime, and prior on startup from config file.

Now i also want to delete rows, but for that i need something to happen when i click the "delete" bitmap image which is in every row on the first column. But i have no idea how to target it, or how to create a mouseclick event which i can tie to my ,not in XAML created, grid.

Here is an image of my page and the grid:
https://ibb.co/npJgoo

What I have tried:

I searched the web but because i am pretty new to c# i found nothing waaaay too complex for me I to be able to solve the problem

推荐答案

您最好的选择可能是使用混合行为而不是复杂c# - 如何在样式设置器中添加混合行为 - 堆栈溢出 [< a href =https://stackoverflow.com/questions/1647815/how-to-add-a-blend-behavior-in-a-style-settertarget =_ blanktitle =New Window> ^ ]。



更高级的用户可以使用他们自己的自定义WPF行为,这通常会转换为cer事件(例如鼠标点击)调用绑定命令。



所以,如果你只想解决当前的问题或者一般的WPF行为,你要么想要研究混合行为如果你想更多地了解技术方法(那里确实有很多内容)。
Your best option is probably to use a Blend Behavior which is not to complex c# - How to add a Blend Behavior in a Style Setter - Stack Overflow[^].

More advanced users can use their own custom WPF Behaviors, which typically translates a certain event (eg. mouse click) into an invocation of a bound command.

So, you either want to research Blend behaviors if you just want to solve your current problem or WPF behaviors in general if you want to understand more about the technical approach (there really is a lot of content out there).


这篇关于当我单击单元格中的特定WPF网格单元格/控件时,如何触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆