Ibraheem Osama Mohamed (ابراهيم اسامه محمد)

Welcome to my blog :)

Access a Control(Button,TextBox) in UserControl in Xaml from another Page

with 4 comments

After adding the userControl in our Xaml code how can we access it’s controls ??  What we need is a reference to the control.

From the last post we added a userControl called flyout (in the last example there is no textbox in the flyout called NameTextBox this is just an example but there is a SaveButton and deleteButton)

            TextBox nameTextbox = flyout.FindName(“NameTextBox”) asTextBox;

            string name = nameTextbox.Text;


            Button addbutton = flyout.FindName(“SaveButton”) asButton;

            Button deletebutton = flyout.FindName(“deleteButton”) asButton;

            addbutton.Click += (a, b) => { EnteryStoryboard.Begin(); };

            deletebutton.Click += (a, b) => { EnteryStoryboard.Begin(); }; 

but take care of you write the name wrong in the FindName method you’ll get a null reference exception


Written by Ibraheem Osama Mohamed

July 31, 2012 at 4:03 pm

4 Responses

Subscribe to comments with RSS.

  1. مشكور, لكن هل هناك من طريقة للدخول على المركبات من الإكس إم إل ؟
    يعني مثلا :


    محمد حاج يحيى

    January 8, 2013 at 9:13 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: