반응형
WPF C# 패스: 패스 데이터가 있는 문자열에서 코드(XAML 이외)로 지오메트리로 이동하는 방법
Code에서 WPF Path 개체를 생성합니다.
XAML에서는 다음을 수행할 수 있습니다.
<Path Data="M 100,200 C 100,25 400,350 400,175 H 280">
어떻게 하면 Code에서도 같은 일을 할 수 있을까요?
Path path = new Path();
Path.Data = "foo"; //This won't accept a string as path data.
PathData를 사용하여 문자열을 PathGeometry로 변환하는 클래스/메서드가 있습니까?
XAML이 해석되고 데이터 문자열이 변환되는 것은 확실합니까?
var path = new Path();
path.Data = Geometry.Parse("M 100,200 C 100,25 400,350 400,175 H 280");
Path.Data는 지오메트리 유형입니다.사용.
리플렉터 JustDecompile(eff Red Gate)에서 TypeConverterAttribute(xaml 시리얼라이저가 타입의 값을 변환하기 위해 사용하는)의 지오메트리의 정의를 확인했습니다.string
로.Geometry
Geometry Converter가 표시되었습니다.실장을 확인해보니 이 제품은Geometry.Parse
경로의 문자열 값을 지오메트리 인스턴스로 변환합니다.
바인딩 메커니즘을 사용할 수 있습니다.
var b = new Binding
{
Source = "M 100,200 C 100,25 400,350 400,175 H 280"
};
BindingOperations.SetBinding(path, Path.DataProperty, b);
도움이 됐으면 좋겠네요.
원래 텍스트 문자열에서 형상을 만들려면 시스템을 사용할 수 있습니다.창문들.Media. 포맷 완료BuildGeometry() 메서드를 사용한 텍스트 클래스
public string Text2Path()
{
FormattedText formattedText = new System.Windows.Media.FormattedText("Any text you like",
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface(
new FontFamily(),
FontStyles.Italic,
FontWeights.Bold,
FontStretches.Normal),
16, Brushes.Black);
Geometry geometry = formattedText.BuildGeometry(new Point(0, 0));
System.Windows.Shapes.Path path = new System.Windows.Shapes.Path();
path.Data = geometry;
string geometryAsString = geometry.GetFlattenedPathGeometry().ToString().Replace(",",".").Replace(";",",");
return geometryAsString;
}
언급URL : https://stackoverflow.com/questions/2029680/wpf-c-sharp-path-how-to-get-from-a-string-with-path-data-to-geometry-in-code-n
반응형
'itsource' 카테고리의 다른 글
Mongoose Error [Mongoose Server Selection Error] : 52.6.250.237:27017에 대한 연결이 닫혔습니다. (0) | 2023.04.22 |
---|---|
Swift를 사용하여 iOS에서 문자열을 MD5 해시로 변환하려면 어떻게 해야 합니까? (0) | 2023.04.22 |
파란색 서비스 버스 대기열을 한 번에 지웁니다. (0) | 2023.04.22 |
Objective-C의 typedef 열거란 무엇입니까? (0) | 2023.04.22 |
신호로 인해 명령이 실패했습니다.세그멘테이션 장애: 11 (0) | 2023.04.17 |