Page view counter
How to switch userControls in code? Subscribe to this thread
Last post 03-11-2008 4:28 PM by CraigN. 3 replies.
Sort Posts:
03-11-2008 10:15 AM
How to switch userControls in code?

Hello

I have 2 user controls in my project : 1- authentification form - AuthForm and 2 - ChatForm

AuthForm user control has event UserAuthentificated.

How can i switch between these controls in code? I mean when user is authetificated then AuthForm control shold be replaced byChatForm

public partial class App : Application

{

    public App()

    {

        this.Startup += this.Application_Startup;

        this.Exit += this.Application_Exit;
        this.UnhandledException += this.Application_UnhandledException;

        InitializeComponent();

    }

   
private void Application_Startup(object sender, StartupEventArgs e)

    {

        var AuthForm = new AuthForm();

        this.RootVisual = AuthForm;

        AuthForm.UserAuthentificated += new UserAuthEventHandler(AuthForm_UserAuthentificated);

    }

    private void Application_Exit(object sender, EventArgs e){}

    private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e){}

    void AuthForm_UserAuthentificated(object sender, UserAuthEventArgs e)

    {

        var chatForm = new ChatForm();        this.RootVisual = chatForm;

    }

}

It doesn`t work

Kostja

Loading...
Joined on 03-07-2008
Posts 16
03-11-2008 12:15 PM
Marked as Answer
Re: How to switch userControls in code?

Kostja,

You could create a container control as your RootVisual and then let the container control orchestrate the display of the authentication and chat forms.
 

If this has answered your question, please click on "Mark as Answer" on this post.

Thanks,
Page Brooks
Silverlight MVP, MCSD
PageBrooks.com | @pbrooks

pbrooks

Loading...
Joined on 03-23-2006
Florence, SC
Posts 323
03-11-2008 3:45 PM
Marked as Answer
Re: How to switch userControls in code?

I tried this out and looked at the source for the RootVisual property. It goes off into some unmanaged code. I have however found a post from Pete Brown explaining it.

I suppose the general way you would have to do this would be to make some form of UserControl container class as was suggested above. I'm seeing if I can mock you one up quickly. If you beat me to it, post it here.

Microsoft Xbox MVP

CraigN

Loading...
Joined on 05-11-2007
South Africa
Posts 89
03-11-2008 4:28 PM
Marked as Answer
Re: How to switch userControls in code?

I decided to post the solution on my blog over here. Hope it helps you out.

Microsoft Xbox MVP

CraigN

Loading...
Joined on 05-11-2007
South Africa
Posts 89
Microsoft Communities