任何类型的system.windows.controls作为函数[C#]中的参数 [英] Any type of system.windows.controls as a parameter in a function [C#]
本文介绍了任何类型的system.windows.controls作为函数[C#]中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个将PreviewMouseDown事件分配给任何类型的System.Windows.Controls的函数。但是我应该输入什么作为参数呢?
我尝试了什么:
对于尝试这样的事情感到愚蠢
I'm trying to create a function that assigns a "PreviewMouseDown" event to any type of System.Windows.Controls. But what should I type as a parameter?
What I have tried:
feel silly for trying something like this
public static void dragcontrol(object ctrl)
{
ctrl.GetType() test = ctrl as System.Windows.Controls;
}
推荐答案
它必须是一个来自UIElement的控件,所以不会是每个控件< br $>
It will have to be a control that derives from UIElement, so that's not going to be every control
private void Attach(System.Windows.UIElement uiElement)
{
uiElement.PreviewMouseDown += UiElement_PreviewMouseDown;
}
这篇关于任何类型的system.windows.controls作为函数[C#]中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文