एक बेहतर समाधान अपने रास्तों स्टोर करने के लिए एक या अधिक System.Windows.Media.Geometry वस्तु का उपयोग किया जाएगा, आदि
यह ज्यामिति एक पेन के साथ तैयार किया जा सकता अंक ताकि आप वास्तव में स्ट्रोक को बदल सकता है जब आप ज़ूम करते हैं तो मोटाई, लेकिन ट्रांसफॉर्म प्रॉपर्टी का उपयोग करना अधिक लचीला है।
ट्रांसफॉर्म का उपयोग करके, आप ज्यामितीय प्रतिनिधित्व के वास्तविक निर्देशांक को "ज़ूम" कर सकते हैं, न कि विज़ुअलाइज़ेशन - इसलिए जब आप इसे आकर्षित करते हैं, तो आपको रेंडर ट्रांसफॉर्म के साथ बेवकूफ़ बनाने की आवश्यकता नहीं होती है।
गणना करने के लिए बदलना, मैं जैसे निम्नलिखित कोड का उपयोग करें:
public static Matrix TransformShape(Rect fromPosition, Rect toPosition, bool flipVertical) {
Matrix translateThenScale = Matrix.Identity;
//we first translate to origin since that's just easier
translateThenScale.Translate(-fromPosition.X, -fromPosition.Y);
//now we scale the graph to the appropriate dimensions
translateThenScale.Scale(toPosition.Width/fromPosition.Width, toPosition.Height/fromPosition.Height);
//then we flip the graph vertically around the viewport middle since in our graph positive is up, not down.
if (flipVertical)
translateThenScale.ScaleAt(1.0, -1.0, 0.0, toPosition.Height/2.0);
//now we push the graph to the right spot, which will usually simply be 0,0.
translateThenScale.Translate(toPosition.X, toPosition.Y);
return translateThenScale;
}
जहां fromPosition रेक्ट untransformed सीमा को शामिल करना चाहिए, और toPosition रेक्ट तब्दील सीमा में होना चाहिए। यह एक्स और वाई को अलग-अलग स्केल करने की भी अनुमति देता है, जो अक्सर साजिश के लिए आवश्यक होता है।
यह अपने ज्यामिति की सीमा की गणना करना आसान है:
Geometry graphGeom;
//[...]
//the bounds are modified by the transform, so we want no transform!
graphGeom.Transform = Transform.Identity;
Rect graphBounds = graphGeom.Bounds;
//then set the transform again
//or, if the transform is axis-aligned, the following _should_ work:
Rect graphBoundsAlt = graphGeom.Transform.Inverse.TransformBounds(graphGeom.Bounds);
और निश्चित रूप से WPF जो सीमा आप में प्रस्तुत करने के लिए की जरूरत है, कि आवश्यक होना चाहिए आप बता सकते हैं। यह एक साथ रखें, आप की तरह
public void RecomputeTransform(Rect targetRect, bool flipVertical) {
graphGeom.Transform = Transform.Identity;
Rect graphBounds = graphGeom.Bounds;
Matrix transMat = TransformShape(graphBounds,targetRect,flipVertical);
graphGeom.Transform = new MatrixTransform(transMat);
}
कुछ कर सकते हैं इस समाधान का उपयोग करने का लाभ यह है कि आप RenderTransforms साथ गड़बड़ की जरूरत नहीं है, आप का उपयोग करने के लिए स्वतंत्र हैं है बदल देती है कि कतरनी और/या पैमाने एक्स और वाई स्वतंत्र रूप से आपकी लाइनों में अजीब विकृतियों के बिना, और आप पेन को एक अपारदर्शी वस्तु के रूप में देख सकते हैं (यानी यूआई से कस्टमाइज़ करना आसान है - यदि आप पेन चौड़ाई या व्हाट्नॉट का चयन करते हैं, तो कोई और सुधार आवश्यक नहीं है)।
यह ठीक है अगर आपके एक्स और वाई स्केल वर्दी हैं, लेकिन स्केल एक जैसे नहीं हैं तो काम नहीं करते हैं। – Klay