Hello everyone,

I am developing a WPF application in which there is a header (user control) with some buttons as "Home", "Upload", "Log Off" etc.
What I want is to add this header user control in a page and when I click the "Upload" button of this header user control, another user control named "FileUpload" should be added to the same page.

I tried

Windows.GetWindow(this).Content=fileuploadobject

in the code behind of header.xaml.cs but it replaces the content however I want to add the file upload user control to the page itself and don't want to replace the page's contents with this file upload user control.

Any help is highly honored.

Thank you very much in advance.

Someone please help me with this issue.

Thanks in advance.

The Conent property only supports one visual element. If you want to add another, you'll need to use a Panel, such as a Grid, Canvas, DockPanel or just about anything else that dervies from the Panel class. Assuming you are using XAML (if not, you should) it would look something like this:

<Window x:Class="Namespace.MainWindow">
    <Grid x:Name="myGrid">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition/>
        </RowDefinition>
        <HeaderControl .../>
    </Grid>
</Window>

If you then accessed it from within the MainWindow (or whatever yours is called), you could do something like:

Grid.SetRow(fileuploadobject, 1);
myGrid.Children.Add(fileuploadobject);

If it's not within the class, you could either cast the instance of the Window to MainWindow and set the access modifier for myGrid to public, or cast the Content property to a Grid.

Btw, I'm a desktop developper, so the control types you may use could differ if you are using Silverlight, but the idea should be the same.

Thanks a lot...really appreciate your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.