views:

283

answers:

2

Hi

Im using pages in the WPF project that im currently working on. However i can't seem to figure out how to change the width of a page, or rather, the width of the window that hosts the pages?

Setting the page width property only changes the width of the page inside the window frame.

Setting the with of the mainwindow or navigationwindow through:

<Application.MainWindow>
    <Window Width="400" />
</Application.MainWindow>

<Application.MainWindow>
    <NavigationWindow Width="400" />
</Application.MainWindow>

Doesnt work either. So how do i set the width of the window in XAML?

A: 

If you're just asking how to set the dimensions of the Window itself, then just open up the Window's XAML file and set the Width/Height properties:

Window Width="640" Height="480"

If you actually want a diff. Window size per Page, you need to do some more work. The available real-estate for a Page is controlled by the host Window. There is no intrinsic way for a Page to ask for more real estate from the host, but you could build support into your iwn app by creating some attached propertirs which your host window knows about and can be applied by the Page author. When the page loads your host can check to see if these properties are set and adjust its own width accordingly.

Drew Marsh
Thanks for the answer, but i think you misunderstand my problem:I just want to set the width of the host window once at compile time, nothing else. So it's not so much the page width that i want to control, but the window frame width, if that makes sense.
Kaare Mai
A: 

It is indeed a pain: you need a NavigationWindow that can navigate to the page. As this inherits from Window you can set the Height and Width on this container.
-Open a new wpf aplication
-delete the standard window1 you get.

Change the App.xaml thus (delete the StartupUri attribute):

<Application x:Class="WpfApplication1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Startup="Application_Startup">
<Application.Resources>

</Application.Resources>
</Application>

Write the App.xaml.cs thus:

    public partial class App : Application
{
    private NavigationWindow navigationWindow;

    private void Application_Startup(object sender, StartupEventArgs e)
    {
        navigationWindow = new NavigationWindow();
        navigationWindow.Height = 200;
        navigationWindow.Width = 100;
        var page = new Page1();
        navigationWindow.Navigate(page);
        navigationWindow.Show();
    }

you can add a page from the project menu. This will give you something like:

<Page x:Class="WpfApplication1.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page1">
<Grid>
    <TextBlock>test</TextBlock>
</Grid>
</Page>

Good luck!

Dabblernl
Thank you, that is exactly what i need! This way it's also possible to set other things like the ReSizeMode etc.
Kaare Mai