开发者

Accessing XAML object in codebehind(WPF)

I'm creating object in XAML like this

<Window.Resources>
        <local:DataReceiver x:Key="request">
        </l开发者_如何学Cocal:DataReceiver>
    </Window.Resources>

how can I call this objects method from codebehind?


var dataReceiver = (DataReceiver)FindResource("request");
...


DataReceiver request = this.TryFindResource("request") as DataReceiver;
if (request != null)
{
   // your code here
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜