我想将它的四个角变成圆角要怎么办呢?
解决方案 »
- 一个C# 关于ListView控件类的一个小问题
- StreamWrite Flush()或Close()时出错
- c#调用c++写的dll,参数类型为stl::map怎么解决?
- DataGridView控件绑定实体的问题(高难度!)
- 关于property文件的操作,保存配置文件的问题
- 怎样让鼠标进入pictureBox指定区域内变成手形?
- [求助]有关于C#中的线形图表的问题,请大虾帮忙。。有点急啊
- 急!为什么在设计窗体中的控件全消失了,但是他们的属性还在,在InitializeComponent还有他们的设置?
- 基于web页面的上传能否续传?
- 如何分区?
- 大家看一下这几句代码!
- 串口发送文本文件,接收的数据需要进行相关处理,接收数据和发送的不一样
<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;
}
}
通过Rect做不了右下角圆角,这个需要你自己做个Path,然后用来做Clip
这个需要你自己做个Path,然后用来做Clip
可以写个伪代码给我看看么?看接触WPF不久
我已经画好一个Path,下一步呢?
<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>
<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>
但是我的这个没有效果
<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>