2011-11-06 4 views
0

저는 wpf를 처음 사용합니다. 나는 두 요소 TextBlock의 및버튼 안에 요소를 구성하는 방법

문제는 내가 그것을 정적 값을 제공하지 않는 한 내가 전혀 캔버스를 볼 수없는 것입니다 캔버스를 캡슐화 뷰 박스를 배치해야합니다 그것의 WPF 버튼, 있어 크기

<Button Margin="10,30,10,10" Padding="0"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="1*"/> 
      <ColumnDefinition Width="2*"/>       
     </Grid.ColumnDefinitions> 

     <TextBlock Text="Me" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></TextBlock> 
     <Viewbox Margin="0,0,0,5"> 
      <Canvas Background="red" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Row="0" Grid.Column="1" > 
        <Ellipse HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stroke="Black" StrokeThickness="4" ></Ellipse>       
      </Canvas> 
     </Viewbox> 
    </Grid> 
</Button> 

iv'e 또한 캔버스

내가 잘못하고있는 무슨의 생각을 표시하지 않는 경우에 수평 orintation 와 스택 패널을 사용하여이 시도? 덕분에 .

답변

1
  1. 캔버스에 설정 한 속성이 적용되지 않습니다 즉 그리드 - 하위 수준에서, 그들은 용기, 그리드의 직접적인 아이 인 뷰 박스에 설정해야 할 때 그리드 속성에만 작동 첨부 .

  2. 콘텐츠가 구체적인 크기 인 경우에만보기 상자가 작동하므로 ViewBox 나 Canvas가 필요하지 않습니다. 당신이 타원이 원하는 경우 원은 HorizontalContentAligment을 설정해야 기본 및 Stretch에 수직 대응에 의해 Stretch="Uniform"

  3. 버튼의 내용은 스트레칭하지 않습니다를 설정합니다.

<Button Margin="10,30,10,10" Padding="0" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch"> 
    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="*" /> 
     </Grid.RowDefinitions> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="1*" /> 
      <ColumnDefinition Width="2*" /> 
     </Grid.ColumnDefinitions> 

     <TextBlock Text="Me" Grid.Row="0" Grid.Column="0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch"></TextBlock> 
     <Ellipse Stretch="Uniform" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" 
       Stroke="Black" StrokeThickness="4"></Ellipse> 
    </Grid> 
</Button> 
+0

이 경우보기 상자와 캔버스를 사용하는 경우는 언제입니까? 타원이 내가 그릴 필요가있는 유일한 요소는 아니며, 예를 들어 여기서는 그림과 단추가 들어갈 텍스트 블록이 필요합니다. 어떻게 구현할 수 있습니까? –

+0

@eranotzer : Shapes의 크기를 정의하면 잘 작동합니다. 캔버스는 절대 위치 지정에 적합합니다. 모든 모양이 중심에 있으면 그리드에 배치 할 수 있습니다. –

관련 문제