2013-03-19 3 views
3

this question을 참조하면 사용자 컨트롤에 그리드 선을 사용하려고했습니다. 디자인 타임에 컨트롤이 좋아 보인다,하지만 난 내 메인 창에 구성 요소를 삽입 할 때 모든 그리드 선이 사라진 대신 그 추악한 회색 코너가 있습니다 :이의WPF 캔버스의 그리드 선

<UserControl x:Class="mx_sachdaten.View.FormWorkspaceView" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
     mc:Ignorable="d" Loaded="FormWorkspaceView_Loaded" 
     d:DesignHeight="400" d:DesignWidth="400"> 
    <UserControl.Resources> 
     <DrawingBrush x:Key="FormCanvasGridTile" Stretch="None" TileMode="Tile" 
        Viewport="0,0,30,30" ViewportUnits="Absolute"> 
      <DrawingBrush.Drawing> 
       <GeometryDrawing> 
        <GeometryDrawing.Geometry> 
         <GeometryGroup> 
          <LineGeometry StartPoint="0,0" EndPoint="30,0" /> 
          <LineGeometry StartPoint="30,0" EndPoint="30,30" /> 
          <LineGeometry StartPoint="30,30" EndPoint="0,30" /> 
          <LineGeometry StartPoint="0,30" EndPoint="0,0" /> 
         </GeometryGroup> 
        </GeometryDrawing.Geometry> 
        <GeometryDrawing.Pen> 
         <Pen Thickness="1" Brush="LightGray" /> 
        </GeometryDrawing.Pen> 
        <GeometryDrawing.Brush>White</GeometryDrawing.Brush> 
       </GeometryDrawing> 
      </DrawingBrush.Drawing> 
     </DrawingBrush> 
    </UserControl.Resources> 
    <Grid> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="*" /> 
      <ColumnDefinition Width="Auto" /> 
     </Grid.ColumnDefinitions> 

     <Canvas Grid.Column="0" x:Name="FormCanvas" Background="{StaticResource FormCanvasGridTile}" 
      MouseLeftButtonDown="FormCanvas_MouseLeftButtonDown" VerticalAlignment="Stretch" 
      HorizontalAlignment="Stretch" /> 
     <ToolBarTray Grid.Column="1" Orientation="Vertical"> 
      <ToolBar Band="1"> 
       <Button Content="Label" HorizontalAlignment="Right" /> 
       <Button Content="TextBox" HorizontalAlignment="Right" /> 
       <Button Content="Button" HorizontalAlignment="Right" /> 
      </ToolBar> 
     </ToolBarTray> 
    </Grid> 
</UserControl> 

결과 : User control preview

는 그리고 이것은 내 메인 창에 보이는 방법입니다 Main window

당신이 내 창에 사용자 정의 컨트롤을 삽입 할 때 내 배경 타일이 제대로 작동하지 않을 이유는 어떤 생각을 가지고 있습니까?

답변

9

이 시도 :

<Border> 
    <Border.Background> 
     <VisualBrush TileMode="Tile" 
      Viewport="0,0,50,50" ViewportUnits="Absolute" 
      Viewbox="0,0,50,50" ViewboxUnits="Absolute"> 
      <VisualBrush.Visual> 
       <Rectangle Stroke="Darkgray" StrokeThickness="1" Height="50" Width="50" 
       StrokeDashArray="5 3"/> 
      </VisualBrush.Visual> 
     </VisualBrush> 
    </Border.Background> 
</Border> 
+0

이 실 거예요 작업 올바르게 경우 – GorillaApe

+1

@Parhs 경우 아래? –

+0

줌 기능이있는 그리기 응용 프로그램이있는 경우를 대비해서 말입니다. 반올림 오류 때문에 격자 선이 잘못 배치됩니다. 그리고 적응 형 그리드 크기를 가진 오토 캐드는 내 줌 환경에서 – GorillaApe