2009-09-03 2 views
5
<Window x:Class="MyWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:src="clr-namespace:WpfApplication1" 
    Title="ContactsSelector" Height="300" Width="300"> 
    <Window.Content> 
     <src:MyPage> 
      <!--MyPage is a page that I created and exists in the project--> 
     </src:MyPage> 
    </Window.Content> 
</Window> 

프로그래밍 방식으로하는 것처럼 창 내용을 페이지에 설정하고 싶습니다.Window.Content를 XAML로 페이지에 설정 하시겠습니까?

Dim w As New MyWindow 
Dim p As New MyPage 
w.Content = p 
w.ShowDialog() 

또는 Window의 Load 이벤트에서 설정하면 요약 할 수 있습니다. xaml에서.

답변

9

페이지의 콘텐츠를 표시하려면 프레임 요소를 사용하십시오.

<Window> <Frame Source="/Pages/MyPage.xaml"/> </Window> 
3

시도 뭔가, 페이지가있는 어셈블리에 MyPageAssembly 포인트 및 마이 페이지는 페이지의 이름입니다.

<Window 
    x:Class="MyWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:MyPageAssembly="clr-namespace:MyPage;assembly=MyPageAssembly" 
    Title="ContactsSelector" 
    Height="300" 
    Width="300" 
    > 
    <Window.Content> 
     <MyPageAssembly:MyPage /> 
    </Window.Content> 
</Window> 
+0

까다로운 스타일 포인트 : 콘텐츠 윈도우의 content 속성이기 때문에, 당신은 Window.Content를 지정할 필요가 없습니다 : :이 코드는에 해당합니다. – itowlson

+0

게시하기 전에이 코드를 사용합니까? 사촌 나는 내 질문을하기 전에 이미 그것을 시도하고 다음과 같은 오류가 발생 : "유형 'MyPage'인스턴스를 만들 수 없습니다."귀하의 대답은 -1 부적절한 정보에 대한 자격이 될 것입니다 Iam dout – Shimmy

+0

나는이 같은 코드를 많이 사용했습니다 시간 전에, 그리고 만약 당신을 위해 작동하지 않았다면, 그것은 원래의 질문에 언급했다면 유용했을 수도 있습니다. 내 마음 읽기 능력이 약간 녹슬 었어 ... xmlns가 올바르게 정의 되었습니까? MyPage 생성자에 중단 점을 추가하여 해당 코드의 내용이 예외를 throw하는지 확인 했습니까? – user112889

관련 문제