Pedro Leal
Pedro Leal

Reputation: 518

How do I cast an XAML item in its controller? [C#],[Xamarin.Forms]

I'm new to Xamarin and I'm facing a problem when it comes to use a xaml item (A button or Label for example) in the controller of this .xaml file.

I just dont know how to declare the item inside the controller, for example in java we use something like

Button btnSave = (Button) findViewByID(R.xmlFILE.btnSave);

then we can use the "btnSave" as an object inside the class controller, but when it comes to Xamarin.forms, I just cant seem to find how I do that, please help me.

Upvotes: 0

Views: 158

Answers (1)

Jason
Jason

Reputation: 89204

in XAML, assign a name to the control

<Button x:Name="myButton" ... />

then in your xaml.cs file, you just refer to it by name. You don't need to declare it or cast it

myButton.Text = "blah";

Upvotes: 1

Related Questions