0 Replies - 1420 Views - Last Post: 30 October 2011 - 05:07 AM

#1 kirvola  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 30-October 11

C#,WP7 | Adding button to the user control using class method

Posted 30 October 2011 - 05:07 AM

I am developing a user control for WP7 application. I added the control to MainPage.xaml and I want the control to create the button from a class called MyButton using the method Add_button_internal(), but i cant to figure out how to do it.

When i try to use a method Add_button_external();, which is outside the class MyButton, there is no problem.

The code behind file for user control looks like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace PhoneApp4
    public partial class WindowsPhoneControl1 : UserControl
        public WindowsPhoneControl1()

            // THIS WORKS FINE
            LayoutRoot.Children.Add(Add_button_external("button name"));

            // THIS DOESNT WORK :(/>
            MyButton t = new MyButton();
            t.Add_button_internal("button name");

        public Button Add_button_external(string m)
            Button btn = new Button();
            btn.Content = m;
            return btn;  

        public class MyButton
            public MyButton() { }

            public Button Add_button_internal(string n)
                Button btn = new Button();
                btn.Content = n;
                return btn;                    

Can you please help me to solve my problem? Thank you in advance.

Is This A Good Question/Topic? 0
  • +

Page 1 of 1