2014-04-05 4 views
0

기본적으로 응용 프로그램을 실행할 때 나타나는 둥근 모서리가있는 네 개의 빨간색 사각형이 있습니다. 모든 4의 코드는 거의 동일합니다. 문제는 처음 2 개만 나타납니다. 그리고 두 번째 것은 마지막에 잘립니다.C# WPF 모든 사각형을 렌더링하지 않습니다.

단순히 오류가 나타나지 않고 컴파일이나 런타임 예외가 나타나지 않습니다.

여기 여기 내 C# 코드 내 WPF 코드

<Window x:Class="flashing_colors.MainWindow" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    Title="MainWindow" Height="1200" Width="1800"> 
    <Grid> 
     <Rectangle Width="200" Height="700" RadiusX="25" RadiusY="25" Name="rect1" Margin="-400,184,800,185"></Rectangle> 
     <Rectangle Width="200" Height="700" RadiusX="25" RadiusY="25" Name="rect2" Margin="600,184,990,185"></Rectangle> 
     <Rectangle Width="200" Height="700" RadiusX="25" RadiusY="25" Name="rect3" Margin="1000,184,800,185"></Rectangle> 
     <Rectangle Width="200" Height="700" RadiusX="25" RadiusY="25" Name="rect4" Margin="1400,184,800,185"></Rectangle> 
    </Grid> 
</Window> 

입니다.

public partial class MainWindow : Window 
    { 
     public MainWindow() 
     { 
      InitializeComponent(); 
      rect1.Fill = new SolidColorBrush(Color.FromRgb(225, 75, 75)); 
      rect2.Fill = new SolidColorBrush(Color.FromRgb(225, 75, 75)); 
      rect3.Fill = new SolidColorBrush(Color.FromRgb(225, 75, 75)); 
      rect4.Fill = new SolidColorBrush(Color.FromRgb(225, 75, 75)); 
     } 
    } 

다음은 스크린 샷입니다. 단 2 개의 둥근 사각형을 주목하십시오. 2 out of 4 rectangles showing up

답변

2

왼쪽 여백을 1000으로 설정하고 오른쪽을 800으로 설정하면 창의 모든 너비가 1800으로 설정되므로 표시 할 공간이 없으므로 세 번째 사각형은 800에서 500으로 변경하고 세 번째 사각형은 800에서 500으로 변경하십시오. Margin으로 재생하는 대신 수평 방향으로 StackPanel을 사용하는 것이 좋습니다.

<StackPanel Orientation="Horizontal"> 
    <StackPanel.Resources> 
     <Style TargetType="Rectangle"> 
      <Setter Property="Width" Value="200"/> 
      <Setter Property="Height" Value="700"/> 
      <Setter Property="RadiusX" Value="25"/> 
      <Setter Property="RadiusY" Value="25"/> 
      <Setter Property="Margin" Value="30,0,0,0"/> 
      <Setter Property="Fill" Value="CadetBlue"/> 
     </Style> 
    </StackPanel.Resources> 
    <Rectangle Name="rect1"/> 
    <Rectangle Name="rect2"/> 
    <Rectangle Name="rect3"/> 
    <Rectangle Name="rect4"/> 
    </StackPanel> 
+0

나는 그것을 시도 할 것이다. 마진은 VS를 디자이너에서 드래그 할 때 자신의 위치를 ​​설정하는 방법을 기본값으로 사용했습니다. –

+1

위를 확인하십시오. – Maximus

+0

@AlexanderRyanBaggett 왜 내가 * 결코 * 사용자 VS 디자이너 레이아웃을 조정할 수 있습니다. 컨트롤을 렌더링하는 방법을보기 위해서만 사용하기 때문에 앱을 다시 컴파일하지 않아도됩니다. –

관련 문제