-1
Rectangle
및 Text
으로 구성된 사용자 정의 Shape
을 작성했습니다.포함 된 도형에 다른 색상으로 설정 한 사용자 정의 모양 wpf
protected override Geometry DefiningGeometry
{
get
{
var formattedText = new FormattedText(Text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface("Verdana"), 14, Brushes.Transparent);
var chosenTextPoint = new Point
{
X = ((Location.X < BottomRight.X) ? Location.X : BottomRight.X) + 5,
Y = ((Location.Y < BottomRight.Y) ? Location.Y : BottomRight.Y) + 5
};
Stroke = Brushes.ForestGreen;
StrokeThickness = (IsSelected) ? HighlightedValue : HighlightedValue/2;
Rectangle = new Rect(Location, BottomRight);
var rectangleGeometry = new RectangleGeometry(Rectangle);
var textGeometry = formattedText.BuildGeometry(chosenTextPoint);
var combinedGeometry = new CombinedGeometry
{
GeometryCombineMode = GeometryCombineMode.Xor,
Geometry1 = rectangleGeometry,
Geometry2 = textGeometry
};
combinedGeometry.Geometry1.SetValue(FillProperty, Brushes.Blue);
combinedGeometry.Geometry1.InvalidateProperty(FillProperty);
Fill = (IsSelected) ? Brushes.Transparent : null;
return combinedGeometry;
}
}
combinedGeometry
내가 PathGeometry
을 사용 그 전에 내가 최근에 추가 한 뭔가 : 여기에 코드입니다. 두 경우 모두 Rectangle
과 Text
은 같은 색으로 표시되며 동일한 모양 효과가 적용됩니다.
나는 두 가지 방법으로 구분할 수 있습니까? 분리하면 두 요소가 모두 Shape
안에있는 개별 요소가되며 둘 중 하나 또는 둘 모두를 자유롭게 수정할 수 있습니다.
기하학에 채우기 속성을 설정할 수 없습니다. Shape에는 항상 1 개의 Fill 및 1 개의 Stroke가 있습니다. 다른 채우기/획을 원한다면 두 가지 모양을 사용하십시오. – Clemens