2009-08-21 7 views
3

이미지를 사용하여 새 UserControl을 추가하는 창이 있습니다.이 컨트롤을 화면 가운데에 세로 및 가로로 가운데에 배치하기 만하면됩니다. 나는 수직 인물 만 작동시킬 수 있습니다. DockPanel의 콘텐츠를 내 CodeBehind에서 바꾸고 슬라이드 쇼 UI를 시작하기 전에이 시작 화면을 표시하려고합니다. 이는 콘텐츠가 CodeBehind에서 설정되었음을 의미합니다. 내 WindowWPF 컨트롤 중앙에 넣기

:

<Window x:Class="GreenWebPlayerWPF.Window1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="Window1" Height="512" Width="853" WindowStyle="None" WindowState="Maximized" WindowStartupLocation="CenterScreen"> 
    <DockPanel Width="Auto" Height="Auto" Name="TransitionContainer" Background="Black" Margin="0" LastChildFill="True"></DockPanel> 
</Window> 

UserControl :

<UserControl x:Class="GreenWebPlayerWPF.FrontPage" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <DockPanel Background="Black"> 
     <Image Name="image1" Stretch="None" Source="/GreenWebPlayerWPF;component/gw.png" /> 
    </DockPanel> 
</UserControl> 

I 최대화/전체 화면을 사용하고 있습니다.

<Grid> 
    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="*"/> 
     <ColumnDefinition Width="Auto"/> 
     <ColumnDefinition Width="*"/> 
    </Grid.ColumnDefinitions> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="*"/> 
     <RowDefinition Height="Auto"/> 
     <RowDefinition Height="*"/> 
    </Grid.RowDefinitions> 
    <!-- Replace with your UserControl --> 
    <Button Content="Foo" Grid.Column="1" Grid.Row="1"/> 
    </Grid> 

당신은 (당신이해야하는 경우 거기에 DockPanel가) 당신의 DockPanel 스트레칭하는 내부를 고정 할 수 있습니다 :

답변

10

Grid을 사용합니다. 물론 위 코드는 모두 마크 업이지만 코드에서 그리드를 쉽게 만들 수 있습니다.

+0

들으 무리는,이 윈도우 RT – H4mm3rHead

+0

작동합니다. Silverlight 파생물이 더 많습니다. –

+0

XAML 기반의 RT에 스토어 앱을 쓰기 위해 사용되는 프레임 워크 WPF하지 작동하지 않습니다 :-) –

1

페이지에 요소를 가운데 놓으려고 할 때이 문제가 계속 발생합니다. StackPanel 문제는 Orientation이 Horizontal이고 Horizontal이 Vertical 인 경우 VerticalAlignment 효과가 없으면 HorizontalAlignment가 효과가 없다는 것입니다. 따라서 아무런 효과가없는 값을 설정하려고 머리를 두드리는 것입니다. 이런 식으로 작동하는 것은 비논리적이지는 않지만 이것이 오류로보고되면 좋을 것입니다.

내가 발견 한 해결책은 아래에 표시된 것처럼 두 개의 겹쳐진 StackPanels을 가로로 가운데에, 다른 세로를 수직으로 배치하는 것입니다. 부모의 크기를 찾는 것은 중간 패널의 크기를 정하는 데 필요합니다. 그렇지 않으면 평면이고 내용이 숨겨집니다. 절대 값도 사용할 수 있습니다. 비록 만병 통치약이 아니지만 그것은 그리드를 사용하는 것보다 약간 덜 장황하다.

<StackPanel Background="Bisque" Orientation="Vertical" Width="300" Height="300" > 
    <StackPanel HorizontalAlignment="Center" Orientation="Horizontal" 
        Height="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=StackPanel}, Path=ActualHeight}"> 
     <StackPanel VerticalAlignment="Center" Width="200" Height="60" Background="Blue"> 
     </StackPanel> 
    </StackPanel> 
</StackPanel> 
+0

멋지고 이해하기 쉬운 아이디어이지만 추가 컨트롤이 필요하지만 여전히 가장 간단한 방법 중 하나입니다! 나는 이것을 사용하고있다! 너는 내 하루를 구했다. – Sree