C# 在一个位置声明的应用程序宽度和高度

C# 在一个位置声明的应用程序宽度和高度,c#,wpf,xaml,C#,Wpf,Xaml,我有一个WPF应用程序和几个导航页面。到目前为止,应用程序的高度和宽度在主窗口和每个页面中声明。 这是主窗口 <Window x:Class="MyApp.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="My Ap

我有一个WPF应用程序和几个导航页面。到目前为止,应用程序的高度和宽度在主窗口和每个页面中声明。 这是主窗口

<Window x:Class="MyApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="My Application"  Height="350" Width="725" >

然后每一页也有高度和宽度,如下所示

<Page x:Class="MyApp.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
     d:DesignHeight="350" d:DesignWidth="725"
    Title="Page1"  >


是否有一个集中的地方可以有高度和宽度,而不是有这么多的地方?

将值保存为资源,然后将每个页面的值绑定到该资源

编辑:

要将值另存为资源,请在visual studio下的“属性”窗口中,单击文本框右侧的宽度(和高度)小框,然后选择“转换为新资源”。在那里选择
应用程序资源
,并为该值命名

要使用此资源,请设置如下值:

Width = {StaticResource WidthResource}

将值另存为资源,然后将每个页面的值绑定到该资源

编辑:

要将值另存为资源,请在visual studio下的“属性”窗口中,单击文本框右侧的宽度(和高度)小框,然后选择“转换为新资源”。在那里选择
应用程序资源
,并为该值命名

要使用此资源,请设置如下值:

Width = {StaticResource WidthResource}

将值另存为资源,然后将每个页面的值绑定到该资源

编辑:

要将值另存为资源,请在visual studio下的“属性”窗口中,单击文本框右侧的宽度(和高度)小框,然后选择“转换为新资源”。在那里选择
应用程序资源
,并为该值命名

要使用此资源,请设置如下值:

Width = {StaticResource WidthResource}

将值另存为资源,然后将每个页面的值绑定到该资源

编辑:

要将值另存为资源,请在visual studio下的“属性”窗口中,单击文本框右侧的宽度(和高度)小框,然后选择“转换为新资源”。在那里选择
应用程序资源
,并为该值命名

要使用此资源,请设置如下值:

Width = {StaticResource WidthResource}

请注意,您在
页面中看到的宽度和高度仅适用于设计器,在编译时会被忽略(通过设置
mc:Ignorable=“d”
属性)


否则,您可以将宽度和高度存储为资源,但我不确定这是否适用于设计器

请注意,您在
页面
中看到的宽度和高度仅适用于设计器,并且在编译时被忽略(通过设置
mc:Ignorable=“d”
属性)

<Application x:Class="SubSetOf.App"  
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <sys:Double x:Key="SysHeight">100</sys:Double>
        <sys:Double x:Key="SysWidth">200</sys:Double>
    </Application.Resources>
</Application>

<Page x:Class="SubSetOf.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="{StaticResource SysHeight}"
      d:DesignWidth="{StaticResource SysWidth}" 
      Height="{StaticResource SysHeight}" 
      Width="{StaticResource SysWidth}"
      Title="Page1">
    <Grid>
        <TextBox Background="pink"/>
    </Grid>
</Page>

否则,您可以将宽度和高度存储为资源,但我不确定这是否适用于设计器

请注意,您在
页面
中看到的宽度和高度仅适用于设计器,并且在编译时被忽略(通过设置
mc:Ignorable=“d”
属性)

<Application x:Class="SubSetOf.App"  
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <sys:Double x:Key="SysHeight">100</sys:Double>
        <sys:Double x:Key="SysWidth">200</sys:Double>
    </Application.Resources>
</Application>

<Page x:Class="SubSetOf.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="{StaticResource SysHeight}"
      d:DesignWidth="{StaticResource SysWidth}" 
      Height="{StaticResource SysHeight}" 
      Width="{StaticResource SysWidth}"
      Title="Page1">
    <Grid>
        <TextBox Background="pink"/>
    </Grid>
</Page>

否则,您可以将宽度和高度存储为资源,但我不确定这是否适用于设计器

请注意,您在
页面
中看到的宽度和高度仅适用于设计器,并且在编译时被忽略(通过设置
mc:Ignorable=“d”
属性)

<Application x:Class="SubSetOf.App"  
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <sys:Double x:Key="SysHeight">100</sys:Double>
        <sys:Double x:Key="SysWidth">200</sys:Double>
    </Application.Resources>
</Application>

<Page x:Class="SubSetOf.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="{StaticResource SysHeight}"
      d:DesignWidth="{StaticResource SysWidth}" 
      Height="{StaticResource SysHeight}" 
      Width="{StaticResource SysWidth}"
      Title="Page1">
    <Grid>
        <TextBox Background="pink"/>
    </Grid>
</Page>
否则,您可以将宽度和高度存储为资源,但我不确定这是否适用于设计器


<Application x:Class="SubSetOf.App"  
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:sys="clr-namespace:System;assembly=mscorlib"
             StartupUri="MainWindow.xaml">
    <Application.Resources>
        <sys:Double x:Key="SysHeight">100</sys:Double>
        <sys:Double x:Key="SysWidth">200</sys:Double>
    </Application.Resources>
</Application>

<Page x:Class="SubSetOf.Page1"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" 
      d:DesignHeight="{StaticResource SysHeight}"
      d:DesignWidth="{StaticResource SysWidth}" 
      Height="{StaticResource SysHeight}" 
      Width="{StaticResource SysWidth}"
      Title="Page1">
    <Grid>
        <TextBox Background="pink"/>
    </Grid>
</Page>
100 200

100
200

100
200

100
200

在您的资源中:
500
然后在您的视图中
Width=“{StaticResource StandardHeight}”
@johnsmith我更新了我的帖子,在您的资源中提供了更多关于资源的详细信息:
500
然后在您的视图中
Width=“{StaticResource StandardHeight}”
@johnsmith我更新了我的帖子,在你的资源中添加了更多关于资源的细节:
500
然后在你的视图中
Width=“{StaticResource-standardheath}”
@johnsmith我更新了我的帖子,在你的资源中添加了更多关于资源的细节:
500
然后在你的视图中
Width=“{StaticResource-standardheath}”
@johnsmith我更新了我的帖子,提供了更多关于资源的详细信息。我知道这可能是以前问过的问题。这个问题与结束时的问题不同。重复是一页内的大小。@我假设OP能够注意到细微差别和数字,将资源放在资源字典中,将静态资源放在他想要的位置。可能的重复我知道这必须是以前问过的。重复和结束不是同一个问题。重复是一页内的大小。@我假设OP能够注意到细微差别和数字,将资源放在资源字典中,将静态资源放在他想要的位置。可能的重复我知道这必须是以前问过的。重复和结束不是同一个问题。重复是一页内的大小。@我假设OP能够注意到细微差别和数字,将资源放在资源字典中,将静态资源放在他想要的位置。可能的重复我知道这必须是以前问过的。重复和结束不是同一个问题。“重复是一页中的大小。@我有点假设OP能够注意到细微差别和数字,将资源放在资源字典中,将静态资源放在他想要的位置上。