Search Results

Search found 12 results on 1 pages for 'pathgeometry'.

Page 1/1 | 1 

  • Custom Fill Property on PathGeometry in Silverlight

    - by Otaku
    I've been looking at (and getting confused by) Dependency Properties - I'm not sure if this is what I need or if there is something else. I'm looking to something very specific with <Path.Data/> children in Silverlight, in particular <PathGeometry/>, <EllipseGeometry/>, etc. While the <Path/> element has a .Fill property, I'd like to add a .Fill property to any of it's Geometries, meaning it's a different color from it's parent. It could be a <SolidColorBrush/> or <LinearGradientBrush/> color, or a percentage of the parent color (like 20% darker than <Path.Fill/>. Is this possible? Is this a dependency property? How would <RectangleGeometry/>, for example, know that I am trying to fill it with a color? How would I get started? (adding WPF as a tag too as someone who knows WPF may be able to help)

    Read the article

  • WPF PathGeometry/RotateTransform optimization

    - by devinb
    I am having performance issues when rendering/rotating WPF triangles If I had a WPF triangle being displayed and it will be rotated to some degree around a centrepoint, I can do it one of two ways: Programatically determine the points and their offset in the backend, use XAML to simply place them on the canvas where they belong, it would look like this: <Path Stroke="Black"> <Path.Data> <PathGeometry> <PathFigure StartPoint ="{Binding CalculatedPointA, Mode=OneWay}"> <LineSegment Point="{Binding CalculatedPointB, Mode=OneWay}" /> <LineSegment Point="{Binding CalculatedPointC, Mode=OneWay}" /> <LineSegment Point="{Binding CalculatedPointA, Mode=OneWay}" /> </PathFigure> </PathGeometry> </Path.Data> </Path> Generate the 'same' triangle every time, and then use a RenderTransform (Rotate) to put it where it belongs. In this case, the rotation calculations are being obfuscated, because I don't have any access to how they are being done. <Path Stroke="Black"> <Path.Data> <PathGeometry> <PathFigure StartPoint ="{Binding TriPointA, Mode=OneWay}"> <LineSegment Point="{Binding TriPointB, Mode=OneWay}" /> <LineSegment Point="{Binding TriPointC, Mode=OneWay}" /> <LineSegment Point="{Binding TriPointA, Mode=OneWay}" /> </PathFigure> </PathGeometry> </Path.Data> <Path.RenderTransform> <RotateTransform CenterX="{Binding Centre.X, Mode=OneWay}" CenterY="{Binding Centre.Y, Mode=OneWay}" Angle="{Binding Orientation, Mode=OneWay}" /> </Path.RenderTransform> </Path> My question is which one is faster? I know I should test it myself but how do I measure the render time of objects with such granularity. I would need to be able to time how long the actual rendering time is for the form, but since I'm not the one that's kicking off the redraw, I don't know how to capture the start time.

    Read the article

  • How can I use a PathGeometry as a mask for a BitmapSource (or any image data)?

    - by Jedidja
    Assuming I have a BitmapSource (actually I have access to the raw pixels as well if necessary), how can I use a PathGeometry as a mask to cut out certain parts of the image? 01234567890123456789 0 -------------------- 1 | + + | 2 | * | 3 | * ) | 4 | * | 5 | ( | 6 -------------------- Assuming I have a PathGeometry that describes a rectangle that goes from (0, 0) to (8, 3), I would like to be able to get one of the following two images: 01234567890123456789 0 -------------------- 1 | + | 2 | * | 3 | | 4 | | 5 | | 6 -------------------- or 012345678 0 --------- 1 | + | 2 | *| 3 ---------

    Read the article

  • How could I make geometry advanced operations on bezier paths?

    - by yizzreel
    I have a library that draws regular bezier path figures (complex paths formed of a lot of bezier points), using midpoint approximation. I can draw them without problem, but I need to add support for advanced geometry operations: Nearest point of a curve, intersection, figure contains point, and more importantly, path combinations: difference, intersection, exclusive-or, union, ... Is there any good source to get all this? Thanks

    Read the article

  • EllipseGeometry is not rendering in Silverlight

    - by Mark Nelson
    I'm trying to draw a circle in WP7 Silverlight using EllipseGeometry instead of Ellipse. The sample XAML in MSDN does not display anything on the canvas in Visual Studio. If I run the app, it does display in the emulator. <Canvas> <Path Fill="Gold" Stroke="Black" StrokeThickness="1"> <Path.Data> <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50" /> </Path.Data> </Path> </Canvas> Any ideas what is happening?

    Read the article

  • 500 Metro Style WP7 Icons

    - by Bil Simser
    I was inspired by The Noun Project, a project that offers up “Metro-style” icons in SVG format. The project is licensed under a public domain license and while it’s a great project, all of the content is in SVG format. Jon Galloway has a great post (from 2007) talking about the differences between SVG and XAML so I highly recommend that for some background. I thought it would be helpful to the WPF/Windows Phone 7/Silverlight community to provide the content in alternative formats for use in your applications. The Goods I’ve put together a package of the 500 icons (502 actually) in PNG, XAML and the original SVG format along with a couple of sample projects so you can see them in action. There’s a WPF desktop app: And a Windows Phone 7 app: Building It To get all the content first I wrote up a quick program to suck the original SVG files. Luckily they’re all in a common path just named 1.SVG, 2.SVG, and so on. Easy sleazy to grab the contents. Once I had 500 SVG files I used the latest copy of XamlTune, an open source CodePlex project that has a command line conversion tool to convert the directory of SVG files into XAML (the tool also created a PNG file of each SVG so that’s just icing on the cake). Conversions The conversion from SVG to XAML isn’t 100%. While you can just drop the content into a WPF app, it doesn’t work that way for WP7. There are just some small adjustments I made to each format so you’ll have to do the same. Follow the information below or refer to the sample applications. As a sample, here’s an icon we want to use: Here’s the original SVG file: <svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="94.616px" viewBox="0 0 100 94.616" enable-background="new 0 0 100 94.616" xml:space="preserve"> <path d="M25.076,15.639c4.324,0.009,7.824-3.488,7.82-7.82C32.9,3.512,29.4,0.012,25.076,0c-4.313,0.012-7.814,3.512-7.821,7.819 C17.262,12.15,20.763,15.648,25.076,15.639L25.076,15.639z"/> <path d="M4.593,43.388h6.861l4.137-15.135h1.716L13.22,43.388h24.318l-4.389-15.135h1.817l2.32,7.415 c1.08,3.131,3.852,3.851,6.003,1.162l8.375-10.142c2.651-3.42-2.104-7.021-4.844-4.035l-4.993,5.952 c0.007,0.095-0.96-3.278-0.96-3.278c-1.135-3.978-4.918-7.903-10.595-7.922H19.576c-5.071,0.019-9.043,4.434-9.888,7.214 L4.593,43.388L4.593,43.388z"/> <polygon points="56.206,22.753 56.206,7.163 49.192,7.163 49.192,22.753 56.206,22.753 "/> <path d="M79.87,15.738c4.332-0.014,7.831-3.516,7.82-7.82c0.011-4.332-3.488-7.833-7.82-7.82c-4.306-0.013-7.806,3.488-7.821,7.82 C72.064,12.222,75.564,15.725,79.87,15.738L79.87,15.738z"/> <path d="M89.759,89.556v-43.19h5.751V22.804c0.007-3.079-2.757-5.448-6.71-5.449H70.436c-3.65,0.001-4.539,1.186-5.551,2.168 L49.597,37.889c-3.098,3.848,2.428,8.333,5.55,4.743L69.88,25.226v64.43c-0.019,6.475,9.06,6.686,9.081,0.201v-36.58h1.765v36.379 C80.748,96.109,89.772,96.13,89.759,89.556L89.759,89.556z"/> <polygon points="100,54.035 100,45.155 0,45.155 0,54.035 100,54.035 "/> </svg> Here’s the XAML that XamlTune created. It can be used in any WPF app without any changes: <Canvas Name="Layer_1" Width="100" Height="94.616" ClipToBounds="True" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> <Path Fill="#FF000000"> <Path.Data> <PathGeometry FillRule="Nonzero" Figures="M25.076,15.639C29.4,15.648 32.9,12.151 32.896,7.819 32.9,3.512 29.4,0.012 25.076,0 20.763,0.012 17.262,3.512 17.255,7.819 17.262,12.15 20.763,15.648 25.076,15.639L25.076,15.639z" /> </Path.Data> </Path> <Path Fill="#FF000000"> <Path.Data> <PathGeometry FillRule="Nonzero" Figures="M4.593,43.388L11.454,43.388 15.591,28.253 17.307,28.253 13.22,43.388 37.538,43.388 33.149,28.253 34.966,28.253 37.286,35.668C38.366,38.799,41.138,39.519,43.289,36.83L51.664,26.688C54.315,23.268,49.56,19.667,46.82,22.653L41.827,28.605C41.834,28.7 40.867,25.327 40.867,25.327 39.732,21.349 35.949,17.424 30.272,17.405L19.576,17.405C14.505,17.424,10.533,21.839,9.688,24.619L4.593,43.388 4.593,43.388z" /> </Path.Data> </Path> <Path Fill="#FF000000"> <Path.Data> <PathGeometry FillRule="Nonzero" Figures="M56.206,22.753L56.206,7.163 49.192,7.163 49.192,22.753 56.206,22.753z" /> </Path.Data> </Path> <Path Fill="#FF000000"> <Path.Data> <PathGeometry FillRule="Nonzero" Figures="M79.87,15.738C84.202,15.724 87.701,12.222 87.69,7.918 87.701,3.586 84.202,0.0849999999999991 79.87,0.097999999999999 75.564,0.084999999999999 72.064,3.586 72.049,7.918 72.064,12.222 75.564,15.725 79.87,15.738L79.87,15.738z" /> </Path.Data> </Path> <Path Fill="#FF000000"> <Path.Data> <PathGeometry FillRule="Nonzero" Figures="M89.759,89.556L89.759,46.366 95.51,46.366 95.51,22.804C95.517,19.725,92.753,17.356,88.8,17.355L70.436,17.355C66.786,17.356,65.897,18.541,64.885,19.523L49.597,37.889C46.499,41.737,52.025,46.222,55.147,42.632L69.88,25.226 69.88,89.656C69.861,96.131,78.94,96.342,78.961,89.857L78.961,53.277 80.726,53.277 80.726,89.656C80.748,96.109,89.772,96.13,89.759,89.556L89.759,89.556z" /> </Path.Data> </Path> <Path Fill="#FF000000"> <Path.Data> <PathGeometry FillRule="Nonzero" Figures="M100,54.035L100,45.155 0,45.155 0,54.035 100,54.035z" /> </Path.Data> </Path> </Canvas> The XAML works AS-IS in a WPF application but there are some changes I did to get it to work in a WP7 app. Here’s the modified XAML in a WP7 application: <Canvas Grid.Row="0" Grid.Column="0" Name="Icon_1" Width="100" Height="94.616"> <Path Fill="#FF000000" Data="M25.076,15.639C29.4,15.648 32.9,12.151 32.896,7.819 32.9,3.512 29.4,0.012 25.076,0 20.763,0.012 17.262,3.512 17.255,7.819 17.262,12.15 20.763,15.648 25.076,15.639L25.076,15.639z"> </Path> <Path Fill="#FF000000" Data="M4.593,43.388L11.454,43.388 15.591,28.253 17.307,28.253 13.22,43.388 37.538,43.388 33.149,28.253 34.966,28.253 37.286,35.668C38.366,38.799,41.138,39.519,43.289,36.83L51.664,26.688C54.315,23.268,49.56,19.667,46.82,22.653L41.827,28.605C41.834,28.7 40.867,25.327 40.867,25.327 39.732,21.349 35.949,17.424 30.272,17.405L19.576,17.405C14.505,17.424,10.533,21.839,9.688,24.619L4.593,43.388 4.593,43.388z"> </Path> <Path Fill="#FF000000" Data="M56.206,22.753L56.206,7.163 49.192,7.163 49.192,22.753 56.206,22.753z"> </Path> <Path Fill="#FF000000" Data="M79.87,15.738C84.202,15.724 87.701,12.222 87.69,7.918 87.701,3.586 84.202,0.0849999999999991 79.87,0.097999999999999 75.564,0.084999999999999 72.064,3.586 72.049,7.918 72.064,12.222 75.564,15.725 79.87,15.738L79.87,15.738z"> </Path> <Path Fill="#FF000000" Data="M89.759,89.556L89.759,46.366 95.51,46.366 95.51,22.804C95.517,19.725,92.753,17.356,88.8,17.355L70.436,17.355C66.786,17.356,65.897,18.541,64.885,19.523L49.597,37.889C46.499,41.737,52.025,46.222,55.147,42.632L69.88,25.226 69.88,89.656C69.861,96.131,78.94,96.342,78.961,89.857L78.961,53.277 80.726,53.277 80.726,89.656C80.748,96.109,89.772,96.13,89.759,89.556L89.759,89.556z"> </Path> <Path Fill="#FF000000" Data="M100,54.035L100,45.155 0,45.155 0,54.035 100,54.035z"> </Path> </Canvas> All I did was take the data portion and put it directly into a Data attribute on the Path. Note that while it does show up in the app (on the emulator or device) it wouldn’t show up in Visual Studio for me. Maybe some XAML guru out there can tell me why. You can just as easily use the PNG files in WP7 but if you want the crispness of vector graphics, go for the XAML version. Of course with XamlTune being open source you could always modify the output of that program to cater it to your app. If you do make a change that’s worthy please consider submitting a patch to the project so everyone can benefit. Hope this helps and happy programming! Resources and Links Sample Project and Icons XamlTune an open source project to convert SVG to XAML The Noun Project source of the original files Jon Galloways post on SVG and XAML StackOverflow question on converting SVG to XAML

    Read the article

  • Dependency property does not work within a geometry in a controltemplate

    - by Erik Bongers
    I have a DepencencyProperty (a boolean) that works fine on an Ellipse, but not on an ArcSegment. Am I doing something that is not possible? Here's part of the xaml. Both the TemplateBindings of Origin and LargeArc do not work in the geometry. But the LargeArc DependencyProperty does work in the Ellipse, so my DependencyProperty seems to be set up correctly. <ControlTemplate TargetType="{x:Type nodes:TestCircle}"> <Canvas Background="AliceBlue"> <Ellipse Height="10" Width="10" Fill="Yellow" Visibility="{TemplateBinding LargeArc, Converter={StaticResource BoolToVisConverter}}"/> <Path Canvas.Left="0" Canvas.Top="0" Stroke="Black" StrokeThickness="3"> <Path.Data> <GeometryGroup> <PathGeometry> <PathFigure IsClosed="True" StartPoint="{TemplateBinding Origin}"> <LineSegment Point="150,100" /> <ArcSegment Point="140,150" IsLargeArc="{TemplateBinding LargeArc}" Size="50,50" SweepDirection="Clockwise"/> </PathFigure> </PathGeometry> </GeometryGroup> </Path.Data> </Path> </Canvas> </ControlTemplate> What I'm trying to build is a (sort of) pie-shaped usercontrol where the shape of the Pie is defined by DependencyProperties and the actual graphics used are in a template, so they can be replaced or customized. In other words: I would like the code-behind to be visual-free (which, I assume, is good separation). SOLUTION--------------------------(I'm not allowed to answer my own questions yet) I found the answer myself, and this can be useful for others encountering the same issue. This is why the TemplateBinding on the Geometry failed: A TemplateBinding will only work when binding a DependencyProperty to another DependencyProperty. Following article set me on the right track: http://blogs.msdn.com/b/liviuc/archive/2009/12/14/wpf-templatebinding-vs-relativesource-templatedparent.aspx The ArcSegment properties are no DependencyProperties. Thus, the solution to the above problem is to replace <ArcSegment Point="140,150" IsLargeArc="{TemplateBinding LargeArc}" with <ArcSegment Point="140,150" IsLargeArc="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=LargeArc}" Colin, your working example where an 'ordinary' binding was used in the geometry set me on the right track. BTW, love the infographics and the construction of your UserControl in your blogpost. And, hey, that quick tip on code snippets, and especially on that DP attribute and the separation of those DPs into a partial class file is pure gold!

    Read the article

  • How to draw complex shape from code behind for custom control in resource dictionary

    - by HopelessCoder
    Hi I am new to wpf and am having a problem which may or may not be trivial. I have defined a custom control as follows in the resource dictionary: <ResourceDictionary x:Class="SyringeSlider.Themes.Generic" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:SyringeSlider"> <Style TargetType="{x:Type local:CustomControl1}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type local:CustomControl1}"> <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"> <Canvas Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" Name="syringeCanvas"> </Canvas> </Border> </ControlTemplate> </Setter.Value> </Setter> </Style> </ResourceDictionary> Unfortunately I cannot go beyond this because I would like to draw a geometry onto the canvas consisting of a set of multiple line geometries whose dimensions are calculated as a function of the space available in the canvas. I believe that I need a code behind method to do this, but have not been able to determine how to link the xaml definition to a code behind method. Note that I have set up a class x:Class="SyringeSlider.Themes.Generic" for specifically this purpose, but can't figure out which Canvas property to link the drawing method to. My drawing method looks like this private void CalculateSyringe() { int adjHeight = (int) Height - 1; int adjWidth = (int) Width - 1; // Calculate some very useful values based on the chart above. int borderOffset = (int)Math.Floor(m_borderWidth / 2.0f); int flangeLength = (int)(adjHeight * .05f); int barrelLeftCol = (int)(adjWidth * .10f); int barrelLength = (int)(adjHeight * .80); int barrelRightCol = adjWidth - barrelLeftCol; int coneLength = (int)(adjHeight * .10); int tipLeftCol = (int)(adjWidth * .45); int tipRightCol = adjWidth - tipLeftCol; int tipBotCol = adjWidth - borderOffset; Path mySyringePath = new Path(); PathGeometry mySyringeGeometry = new PathGeometry(); PathFigure mySyringeFigure = new PathFigure(); mySyringeFigure.StartPoint = new Point(0, 0); Point pointA = new Point(0, flangeLength); mySyringeFigure.Segments.Add(new LineSegment(pointA, true)); Point pointB = new Point(); pointB.Y = pointA.Y + barrelLength; pointB.X = 0; mySyringeFigure.Segments.Add(new LineSegment(pointB, true)); // You get the idea....Add more points in this way mySyringeGeometry.Figures.Add(mySyringeFigure); mySyringePath.Data = mySyringeGeometry; } SO my question is: 1) Does what I am trying to do make any sense? 2) Can a use a canvas for this purpose? If not, what are my other options? Thanks!

    Read the article

  • WPF custom Button using Geometry from resource

    - by theburningmonk
    Is there a way to use a collection of PathGeometry like these: Path 1 F1 M 170.255,178.837L 170.255,221.158C 170.255,228.917 164.174,230.777 156.745,225.286L 136.003,209.973C 128.572,204.488 128.572,195.512 136.003,190.023L 156.745,174.706C 164.174,169.217 170.255,171.079 170.255,178.837 Z Path 2 F1 M 152.29,174.464L 134.314,187.734C 129.978,190.937 127.589,195.29 127.589,199.994C 127.589,204.7 129.978,209.057 134.314,212.26L 152.29,225.531C 150.333,229.378 145.412,229.52 139.678,225.286L 118.935,209.973C 111.506,204.489 111.506,195.512 118.935,190.022L 139.678,174.708C 145.412,170.475 150.333,170.617 152.29,174.464 Z and use them to make a custom button in the same way you can make a circular button shown in this example? http://www.wpftutorial.net/Templates.html The example involves overriding the control template and it seems a lot of work if I want to have many custom-shaped buttons. And what if I want to load the geometry points from the resource?

    Read the article

  • Issue with child of custom Decorator class in WPF

    - by galacticgrug
    I need a custom border that renders a little differently than a normal border. I made a class that inherited from Decorator as follows class BetterBorder : Decorator { protected override Size ArrangeOverride(Size arrangeSize) { return arrangeSize; } protected override void OnRender(DrawingContext dc) { //these values are calculated elsewhere dc.DrawGeometry(backgroundBrush, borderPen, pathGeometry); } } //Properties and helper methods below this All of this works fine until I try to add a child to the control, the control can be added but is not visible and seems to be moved off BetterBorders visible client area. If I inherit from Border everything works fine, what am I missing?

    Read the article

  • Issue with child of custom Decorator class in WPF (c#)

    - by galacticgrug
    I need a custom border that renders a little differently than a normal border. I made a class that inherited from Decorator as follows class BetterBorder : Decorator { protected override Size ArrangeOverride(Size arrangeSize) { return arrangeSize; } protected override void OnRender(DrawingContext dc) { //these values are calculated elsewhere dc.DrawGeometry(backgroundBrush, borderPen, pathGeometry); } } //Properties and helper methods below this All of this works fine until I try to add a child to the control, the control can be added but is not visible and seems to be moved off BetterBorders visible client area. If I inherit from Border everything works fine, what am I missing?

    Read the article

  • WPF Binding Error reported when Binding appears to work fine

    - by Noldorin
    I am trying to create a custom TabItem template/style in my WPF 4.0 application (using VS 2010 Pro RTM), but inspite of everything seeming to work correctly, I am noticing a binding error in the trace window. The resource dictionary XAML I use to style the TabItems of a TabControl is given in full here. (Just create a simple TabControl with several items and apply the given ResourceDictionary to test it out.) Specifically, the error is occurring due to the following line (discovered through trial and error testing, since Visual Studio isn't actually reporting it at design tim <TranslateTransform X="{Binding ActualWidth, ElementName=leftSideBorderPath}"/> The full error given in the trace (Ouput window) is the following: System.Windows.Data Error: 2 : Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=ActualWidth; DataItem=null; target element is 'TranslateTransform' (HashCode=35345840); target property is 'X' (type 'Double') The error occurs on load and is repeated 5 times then (note that I have 3 tab items in my example). It also occurs consistently and repeatedly whenever for the Window is resized, for example - filling the Output window. Perhaps every time the TabItem layout is updated? And again, though it is not reported, the error very much seems to be due to the fact that I am binding to any element at all, not specifically leftSideBorderPath or the the ActualWidth propertry. For example, changing this line to the following fixes things. <TranslateTransform X="25"/> Unfortunately, hard-coding the value isn't really an option. This issue seems very strange to me in that the binding does appear to be giving the correct results. (Inspecting the X value of the TranslateTransform at runtime clearly shows the correct bound value, and the ClipGeometry when viewed is exactly what it hsould be.) Neither Visual Studio nor WPF seems to be giving me any more information on the cause of the error perhaps (setting PresentationTraceSources.TraceLevel to High doesn't help), yet the fact that things are working despite the error being reported inclines me to think that this is some fringe-case WPF bug. As a side note, the Visual Studio WPF designer and XAML editor are giving me a problem with the following line: <PathGeometry Figures="{Binding Source={StaticResource TabSideFillFigures}}"/> Although WPF (at runtime) is perfectly happy binding Figures to the TabSideFillFigures string, with the Binding enforcing the use of the TypeConverter, the XAML editor and WPF designer are complaining. All the XAML code for the ControlTemplate is underlined and I get the following errors in the Error List: Error 9 '{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Control.Template' property on a Setter. C:\Users\Alex\Documents\Visual Studio 2010\Projects\Ircsil\devel\Ircsil\MainWindow.xaml 1 1 Ircsil Error 10 Object reference not set to an instance of an object. C:\Users\Alex\Documents\Visual Studio 2010\Projects\Ircsil\devel\Ircsil\Skins\Default\MainSkin.xaml 58 17 Ircsil Again, to repeat, everything works perfectly well at runtime, which is what makes this particularly odd... Could someone perhaps shed some light on these issues, in particular the first (which seems to be a potential WPF bug), and the latter (which seems to be a Visual Studio bug). Any sort of feedback or suggestions would be much appreciated!

    Read the article

1