tags:

views:

34

answers:

2

Hi, I'm new in WPF I'm creating object in XAML like this

<Window.Resources>
        <local:DataReceiver x:Key="request">
        </local:DataReceiver>
    </Window.Resources>

how can I call this objects method from codebehind?

+1  A: 
DataReceiver request = this.TryFindResource("request") as DataReceiver;
if (request != null)
{
   // your code here
}
Khyad Halda
Should probably be 'as DataReceiver' rather than 'as Style' :-)
Goblin
problem is that i need to call exactly methode of the object that i created in xlm, without creating new one =\
ZAA
Thanks for the correction :)
Khyad Halda
ZAA - this finds the exact object that was instantiated in XAML.
Khyad Halda
strange cuz my bindings at null? so i sopose that different object =\
ZAA
thanks all, just resolve problem=)
ZAA
+1  A: 
var dataReceiver = (DataReceiver)FindResource("request");
...
Pavel Minaev