2016-08-09 2 views

답변

2
네 개의 별도의 경로 요소로 네 개의 둥근 모서리를 그릴 더 간단 수 있습니다

:

<Grid> 
    <Path HorizontalAlignment="Left" VerticalAlignment="Top" Fill="Red" 
      Data="M0,0 L10,0 A10,10 0 0 0 0,10Z"/> 
    <Path HorizontalAlignment="Right" VerticalAlignment="Top" Fill="Red" 
      Data="M0,0 L0,10 A10,10 0 0 0 -10,0Z"/> 
    <Path HorizontalAlignment="Left" VerticalAlignment="Bottom" Fill="Red" 
      Data="M0,0 L10,0 A10,10 0 0 1 0,-10Z"/> 
    <Path HorizontalAlignment="Right" VerticalAlignment="Bottom" Fill="Red" 
      Data="M0,0 L0,-10 A10,10 0 0 1 -10,0Z"/> 
</Grid> 
+0

이것이 사각형에서 어떻게 작동하는지 알려주십시오. – lokusking

+0

왜 사각형이어야합니까? 색상이 지정된 모서리가있는 투명 오버레이의 종류를 정의하려는 것 같습니다. 위의 표를 사용하면됩니다. – Clemens

3

더 간단한 방법 :

<Rectangle Fill="Red" Height="200" Width="200" > 
       <Rectangle.Clip > 
        <CombinedGeometry GeometryCombineMode="Exclude"> 
         <CombinedGeometry.Geometry1> 
          <RectangleGeometry Rect="0,0,200,200"/> 
         </CombinedGeometry.Geometry1> 
         <CombinedGeometry.Geometry2> 
          <EllipseGeometry x:Name="transparentRect" Center="100 100" RadiusX="120" RadiusY="120"/> 
         </CombinedGeometry.Geometry2> 
        </CombinedGeometry> 
       </Rectangle.Clip> 
      </Rectangle> 
지금은

enter image description here

을,이 코드를했습니다

참고

직사각형의 크기를 변경하면 도형의 직사각형과 반경 값도 조정해야 적절한 비율이 표시됩니다.

몇 분 후에이 작업을 수행 했으므로 개선 할 여지가 있습니다. 전체 만족스러운 접근 방식에 대한

건배

편집

, 난 당신이 컨버터

코드

public class RectangleConverter : IValueConverter { 
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { 
      var recta = value as Rectangle; 
      if (recta == null) return null; 
      return new Rect { X = 0, Y = 0, Height = recta.ActualHeight, Width = recta.ActualWidth }; 
     } 

     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 
      throw new NotImplementedException(); 
     } 
    } 

    public class ElipseGeoConverter : IValueConverter { 
     public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { 
      var recta = value as Rectangle; 
      if (recta == null) return null; 
      return new EllipseGeometry(new Point(recta.ActualWidth/2, recta.ActualHeight/2), recta.ActualWidth/3 * 2, 
       recta.ActualHeight/3 * 2); 
     } 

     public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 
      throw new NotImplementedException(); 
     } 
    } 

사용

를했습니다
<Rectangle Fill="Red" Height="100" Width="100" > 
       <Rectangle.Clip > 
        <CombinedGeometry GeometryCombineMode="Exclude"> 
         <CombinedGeometry.Geometry1> 
          <RectangleGeometry> 
           <RectangleGeometry.Rect> 
            <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Rectangle}}" Converter="{StaticResource RectangleConverter}"></Binding> 
           </RectangleGeometry.Rect> 
          </RectangleGeometry> 
         </CombinedGeometry.Geometry1> 
         <CombinedGeometry.Geometry2> 
          <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type Rectangle}}" Converter="{StaticResource GeoConverter}"/> 
         </CombinedGeometry.Geometry2> 
        </CombinedGeometry> 
       </Rectangle.Clip> 
      </Rectangle> 
+0

그래, 그건 내가 의미 물건의 종류입니다. –

+0

잠시 동안 코드를 테스트 할 수는 없지만 대답 해 주셔서 감사합니다. 겉으로보기에 upvotes에 비추어 볼 때 소리가납니다. :) – Drarig29

+0

어떻게 CombinedGeometry Rect와 Radius-Values를 Rectangle의 ActualWidth 및 ActualHeight 속성에 바인딩 할 수 있습니까? 내 문제는 내 사각형이 현재 Grid에 있고 너비와 높이가 auto로 설정되어 있다는 것입니다. – Drarig29