Change window width when using pages in WPF

Im using the pages in the WPF project that I'm currently working on. However, I cannot understand how to change the width of the page, more precisely, the width of the window on which the pages are placed?

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

Configured using mainwindow or navigationwindow mode via:

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

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

Does not work. So how to set window width in XAML?

+3
source share
2 answers

: NavigationWindow, . , Height Width .
- wpf
-delete 1, .

App.xaml ( StartupUri):

<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>

App.xaml.cs :

    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();
    }

. - :

<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>

!

+2

, , XAML Width/Height:

Window Width="640" Height="480"

diff. , . . , iwn, , . , , .

0

Source: https://habr.com/ru/post/1721028/


All Articles