1

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.

Edited by KM499

2
Contributors
3
Replies
8
Views
4 Years
Discussion Span
Last Post by KM499
Featured Replies
  • 1

    Someone please help me with this issue. Thanks in advance. Read More

  • 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 … Read More

  • 1

    Thanks a lot...really appreciate your help. Read More

1

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.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.