locked
How to access usercontrol's UIElement's property in other userControl or page?

    Question

  • Hi

    I am new in Windows store app development and i am developing windows store app with c# . In my app there is requirement to use user control for reusability but in mainPage i am not able to access button click event of user control did anyone help that how to get that???

    Thank's in advance.

    waiting for the reply

    Wednesday, February 19, 2014 8:07 AM

Answers

  • Hi,

    If you create a button in a userControl, you should register for the Button's Click event in the UserControl. And in the UserControl you should  also create an API and call the Click event. So, When the Button's Click event is fired, the UserControl can listens for it and fires this Click event. A simple example below you can refer to:

    <StackPanel Orientation="Horizontal">
      <src:NameReporter Width="100" RoundValue=" 1" ButtonClick="NameReporter_Click" />
      <src:NameReporter Width="100" RoundValue=" 2" ButtonClick="NameReporter_Click" />
    </StackPanel>
    
    public  partial class NameReporter: UserControl
    {
    	public event EventHandler ButtonClick;
    	
    	public NameReporter()
    	{
    	    this.InitializeComponent();
    	    button.Click+= button_Click;
    	}
    	
    	void button_Click(object sender, TappedRoutedEventArgs e)
    	{
    	    ButtonClick(this, null);
    	}
    }
    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    • Marked as answer by Megha Kevadia Friday, February 21, 2014 5:43 AM
    Thursday, February 20, 2014 2:44 AM