2015-01-23 1 views
0

여러 탐색 페이지가있는 WPF 응용 프로그램이 있습니다. 현재 응용 프로그램 높이와 너비는 MainWindow와 각 페이지에서 선언됩니다.응용 프로그램의 너비와 높이를 한 곳에서 선언했습니다.

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

내가 오히려 많은 장소에서 가지고, 높이와 너비를 가질 수있는 하나 개의 중앙 장소가 될 수 아래 같은 높이와 너비를 가지고 MainWindow를 그래서 여기에 ?

+0

가능한 중복 : //stackoverflow.com/questions/2279732/specify-width-height-as-resource-in-wpf) –

+0

나는 이것이 전에 물어야한다는 것을 알고 있었다. –

+0

복제본은 닫기와 같은 질문이 아닙니다. 중복은 페이지 내의 크기입니다. – Paparazzi

답변

1
<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> 
(HTTP [WPF에서 자원으로 너비/높이 지정]의
1

값을 리소스로 저장 한 다음 각 페이지의 값을 해당 리소스에 바인딩하십시오.

편집 :

는, Visual Studio를 아래의 속성 창에서 자원으로 값을 저장 폭 (높이) 텍스트 상자의 오른쪽에있는 작은 상자를 클릭하고 Convert To New Resource을 선택합니다. There Application Resource을 선택하고 값에 이름을 지정하십시오. 을 설정하여 (당신이 당신의 Page에서 볼 수있는 폭과 높이 디자이너 만하고, 컴파일시에 무시됩니다

Width = {StaticResource WidthResource} 
+1

모든 코드 예? – BKS

+0

당신의 리소스에서 :' 500'보기에서'Width = "{StaticResource StandardHeight}"' –

+0

@johnsmith 자원에 대한 자세한 내용 – pquest

1

참고 :이 자원을 사용하기 위해

이 같은 값을 설정 mc:Ignorable="d" 속성).

그렇지 않으면 당신은 자원과 폭과 높이를 저장할 수 있지만 실제로 디자이너 작동 할 수 모르겠어요

관련 문제