2014-10-14 4 views
0

Как кликать штрих пути? С ClipToBounds="True" есть нежелательные куски на уровне основания и нижней части.wpf ClipToBounds справа и внизу

alt

<Grid Background="Yellow" ClipToBounds="True"> 
    <Viewbox Stretch="Fill"> 
     <Path Data="M30,0 L0,10 L0,40 L30,50 L30,0" Stroke="Red" StrokeThickness="5" /> 
    </Viewbox> 
</Grid> 

EDIT

Я понял, что мне просто не нужно масштабировать толщину границы, так что решение будет:

enter image description here

<Grid x:Name="grid" Grid.Row="2" Background="Yellow" > 
    <Grid.Resources> 
     <ScaleTransform x:Key="transform" 
       ScaleX="{Binding ActualWidth, ElementName=grid}" 
       ScaleY="{Binding ActualHeight, ElementName=grid}" /> 
    </Grid.Resources> 
    <Path Stroke="Red" StrokeThickness="15" Stretch="Fill"> 
     <Path.Data> 
      <PathGeometry Transform="{StaticResource transform}"> 
       <PathGeometry.Figures> 
        <PathFigureCollection> 
         <PathFigure IsClosed="True" StartPoint="0,0.7"> 
          <PathFigure.Segments> 
           <PathSegmentCollection> 
            <LineSegment Point="1,1" /> 
            <LineSegment Point="1,0" /> 
            <LineSegment Point="0,0.3" /> 
           </PathSegmentCollection> 
          </PathFigure.Segments> 
         </PathFigure> 
        </PathFigureCollection> 
       </PathGeometry.Figures> 
      </PathGeometry> 
     </Path.Data> 
    </Path> 
</Grid> 

ответ

0

Если я т нормально не масштабировать толщину обводки, вы можете отказаться от Viewbox и установить Stretch="Fill" непосредственно на пути:

<Grid Background="Yellow" ClipToBounds="True" Margin="20"> 
    <Path Stretch="Fill" Data="M30,0 L0,10 L0,40 L30,50 L30,0 Z" 
      Stroke="Red" StrokeThickness="20" /> 
</Grid> 

В противном случае вы можете использовать путь в VisualBrush в, например, прямоугольник (который должен быть установлен некоторый размер явно):

<Grid Background="Yellow" ClipToBounds="True" Margin="20"> 
    <Viewbox Stretch="Fill"> 
     <Rectangle Width="1" Height="1"> 
      <Rectangle.Fill> 
       <VisualBrush> 
        <VisualBrush.Visual> 
         <Path Data="M30,0 L0,10 L0,40 L30,50 L30,0 Z" 
           Stroke="R*emphasized text*ed" StrokeThickness="5" /> 
        </VisualBrush.Visual> 
       </VisualBrush> 
      </Rectangle.Fill> 
     </Rectangle> 
    </Viewbox> 
</Grid> 

Обратите внимание, что геометрия пути закрывается задний Z.

+0

Не то, что я хочу, но нашел решение [здесь] (http://stackoverflow.com/a/15323221/3009578) – smg