その中に aと aShape
から構成されるカスタムを作成しました。コードは次のとおりです。Rectangle
Text
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
が同じ色で着色されており、同じ形状効果が「被る」。
2つを分離する方法はありますか?分離するということは、両方が 内の個々の要素になることを意味し、それらのShape
いずれかまたは両方を一緒に自由に変更できますか?