我正在像这样在XAML中创建对象
<Window.Resources>
<local:DataReceiver x:Key="request">
</local:DataReceiver>
</Window.Resources>
如何从代码隐藏中调用此对象方法?
答案 0 :(得分:1)
DataReceiver request = this.TryFindResource("request") as DataReceiver;
if (request != null)
{
// your code here
}
答案 1 :(得分:1)
var dataReceiver = (DataReceiver)FindResource("request");
...