2009-10-01 2 views
6

내 프로젝트에서 사용자 지정 컨트롤의 측면에 작은 로고를 표시하려고합니다. 캔버스가 없으므로 비주얼 브러쉬가 배경에 로고를 배치하는 좋은 아이디어 일 수 있다고 생각했습니다.WPF : 도움말! Visual Brush streets all content

<VisualBrush> 
    <VisualBrush.Visual> 
     <Rectangle Width="200" Height="200" Fill="Red" /> 
    </VisualBrush.Visual>     
</VisualBrush> 

하지만 현재 사용중인 사각형은 200x200이 아닙니다. 사용 가능한 전체 공간이 필요합니다. 그게 내가 원하는 걸 그게 아니야. 또한 Viewbox를 시도하고 stretch 속성을 설정했지만 결과적으로 동일한 Rectangle을 필요로하지 않으므로 많은 패스 객체가있는 캔바스가 자식으로 필요합니다. Viewbox는 하나의 자식 만 지원합니다.

이 문제를 해결할 수있는 방법이 있습니까?

답변

10

당신은 당신의 VisualBrushTileMode, Stretch, AlignmentXAlignmentY 속성을 설정해야합니다

<VisualBrush TileMode="None" Stretch="None" AlignmentX="Left" AlignmentY="Top"> 
    <VisualBrush.Visual> 
     <Rectangle Height="200" Width="200" Fill="Red"></Rectangle> 
    </VisualBrush.Visual> 
</VisualBrush> 
+0

완벽하게 작동합니다. 고마워. – TalkingCode

+0

덕분에 TileMode = "None"및 Stretch = "None"이 누락되었습니다. – juFo

0

추가 그리드 및 오른쪽 샘플 코드이 설정 수직 맨 위로 alligment 및 수평 방향의 배치

<VisualBrush x:Key="myVisual"> 
     <VisualBrush.Visual> 
      <Grid> 
       <Rectangle Height="200" Width="200" Fill="Red" HorizontalAlignment="Right" VerticalAlignment="Top" ></Rectangle> 
      </Grid> 
     </VisualBrush.Visual> 
    </VisualBrush>