我想将它的四个角变成圆角要怎么办呢?

解决方案 »

  1.   

    更正一下:我是想StackPanel的右下角变成圆角~
      

  2.   

    以前我在SL中做过让文本框变成圆角的样式。思想是在TextBox外层设一个Boder,然后将Boder的CornerRadius属性设置为5,就是圆角的程度值,Border默认宽度是0,要开改一下。文本框的边框不显示。这样看起来就像是一个圆角的文本框了。当时我做的是一个多行输入框,很大的,所以能看出效果。
      

  3.   


    <control:ClippingBorder CornerRadius="20">
        <StackPanel Background="Yellow">
            <Label>Hello World</Label>
        </StackPanel>
    </control:ClippingBorder>
    ClippingBorder.csusing System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows.Controls;
    using System.Windows.Media;
    using System.Windows;namespace Shgbit.Controls {
    /// <Res>
    ///     As a side effect ClippingBorder will surpress any databinding or animation of 
    ///         its childs UIElement.Clip property until the child is removed from ClippingBorder
    /// </Res>
    public class ClippingBorder : Border {
    protected override void OnRender(DrawingContext dc) {
    OnApplyChildClip();
    base.OnRender(dc);
    } public override UIElement Child {
    get {
    return base.Child;
    }
    set {
    if (this.Child != value) {
    if (this.Child != null) {
    // Restore original clipping
    this.Child.SetValue(UIElement.ClipProperty, _oldClip);
    } if (value != null) {
    _oldClip = value.ReadLocalValue(UIElement.ClipProperty);
    } else {
    // If we dont set it to null we could leak a Geometry object
    _oldClip = null;
    } base.Child = value;
    }
    }
    } protected virtual void OnApplyChildClip() {
    UIElement child = this.Child;
    if (child != null) {
    _clipRect.RadiusX = _clipRect.RadiusY = Math.Max(0.0, this.CornerRadius.TopLeft - (this.BorderThickness.Left * 0.5));
    Rect rect = new Rect(this.RenderSize);
    rect.Height -= (this.BorderThickness.Top + this.BorderThickness.Bottom);
    rect.Width -= (this.BorderThickness.Left + this.BorderThickness.Right);
    _clipRect.Rect = rect;
    child.Clip = _clipRect;
    }
    } public void Update() { OnApplyChildClip(); } private RectangleGeometry _clipRect = new RectangleGeometry();
    private object _oldClip;
    }
    }
      

  4.   

     _clipRect.RadiusX = _clipRect.RadiusY = Math.Max(0.0, this.CornerRadius.TopLeft - (this.BorderThickness.Left * 0.5));
    通过Rect做不了右下角圆角,这个需要你自己做个Path,然后用来做Clip
      

  5.   


    这个需要你自己做个Path,然后用来做Clip
    可以写个伪代码给我看看么?看接触WPF不久
      

  6.   


    我已经画好一个Path,下一步呢?
      

  7.   


    <Path Stroke="Blue">
    <Path.Data>
    <PathGeometry>
    <PathGeometry.Figures>
    <PathFigure StartPoint="0,0" IsClosed="True">
    <LineSegment Point="300,0" />
    <LineSegment Point="300,80" />
    <ArcSegment Point="280,100" Size="20,20" SweepDirection="Clockwise"/>
    <LineSegment Point="0,100" />
    </PathFigure>
    </PathGeometry.Figures>
    </PathGeometry>
    </Path.Data>
    </Path>
      

  8.   

    something like below:<Border Width="300" Height="100">
        <Border.Clip>
            <PathGeometry>
                <PathGeometry.Figures>
                    <PathFigure StartPoint="0,0" IsClosed="True">
                        <LineSegment Point="300,0" />
                        <LineSegment Point="300,80" />
                        <ArcSegment Point="280,100" Size="20,20" SweepDirection="Clockwise"/>
                        <LineSegment Point="0,100" />
                    </PathFigure>
                </PathGeometry.Figures>
            </PathGeometry>
        </Border.Clip>
        <StackPanel Background="Yellow">
            <Label>Hello World</Label>
        </StackPanel>
    </Border>
      

  9.   

    十分感谢
    但是我的这个没有效果
    <Border  BorderBrush="Red" BorderThickness="5" >
            <Border.Clip>
                <PathGeometry>
                    <PathGeometry.Figures>
                        <PathFigure StartPoint="50,50">
                            <LineSegment Point="50,100"></LineSegment>
                        </PathFigure>
                        <PathFigure StartPoint="50,50">
                            <LineSegment Point="100,50"></LineSegment>
                        </PathFigure>
                        <PathFigure StartPoint="50,100">
                            <LineSegment Point="90,100"></LineSegment>
                        </PathFigure>
                        <PathFigure StartPoint="100,50">
                            <LineSegment Point="100,90"></LineSegment>
                        </PathFigure>
                        <PathFigure StartPoint="100,90">
                            <ArcSegment Point="100,90" IsLargeArc="False" SweepDirection="Counterclockwise" Size="10,10"/>
                        </PathFigure>
                    </PathGeometry.Figures>
                </PathGeometry>                         
            </Border.Clip>
            <StackPanel Background="Yellow">        </StackPanel>
        </Border>