PathGeometrry for a lock icon - Xaml - wpf

I'd like to create a PathGeometry for a lock icon in xaml. Are there any tools to help me with that?

The way Geometry works seems complicated, but once you understand how it works, you can use Vector-based icons that are better than images. Give it a try it.
You can use Geometry in this way.
First, A string-based Geometry value is required.
M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z =
<Geometry x:Key="ICON">
M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z
</Geometry>
And Path is required to print Geometry on the screen.
<Path Data="{StaticResource ICON}" Width="48" Height="48"/>
It is recommended that the Path size is the same as the Path actual size. Because adjusting the size with ViewBox is a way to better utilize the characteristics of Vector.
Finaly
below is how to apply this method to use icons.
lock-outline
<Viewbox Width="48" Height="48">
<Canvas Width="24" Height="24">
<Path Fill="Black" Data="M12,17C10.89,17 10,16.1 10,15C10,13.89 10.89,13 12,13A2,2 0 0,1 14,15A2,2 0 0,1 12,17M18,20V10H6V20H18M18,8A2,2 0 0,1 20,10V20A2,2 0 0,1 18,22H6C4.89,22 4,21.1 4,20V10C4,8.89 4.89,8 6,8H7V6A5,5 0 0,1 12,1A5,5 0 0,1 17,6V8H18M12,3A3,3 0 0,0 9,6V8H15V6A3,3 0 0,0 12,3Z" />
</Canvas>
</Viewbox>
lock-open-variant-outline
<Viewbox Width="48" Height="48">
<Canvas Width="24" Height="24">
<Path Fill="Black" Data="M10 13C11.1 13 12 13.89 12 15C12 16.11 11.11 17 10 17S8 16.11 8 15 8.9 13 10 13M18 1C15.24 1 13 3.24 13 6V8H4C2.9 8 2 8.9 2 10V20C2 21.1 2.9 22 4 22H16C17.1 22 18 21.1 18 20V10C18 8.9 17.1 8 16 8H15V6C15 4.34 16.34 3 18 3S21 4.34 21 6V8H23V6C23 3.24 20.76 1 18 1M16 10V20H4V10H16Z" />
</Canvas>
</Viewbox>
And the site below offers many different open-source icons. You can choose it yourself and provide it with Xaml source code. I also use this website a lot. Here

Related

Best practice to for storing SVG in React app?

The question may be trivial but I am a bit confused. I imported to my React app some SVG files and I wonder what is the best place to keep them to have a clean file structure. I have two folders that I assume could be the best for them. The first is ./src/Assets/Icons folder and another one is the ./src/Components/Icons folder.
I am using SVG as a component like here so I am not sure if it will be better to have them in Assets or in Components. What are your best practices and how do you approach that?
return (
<svg
width="35"
height="36"
viewBox="0 0 35 36"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M30.8385 0.414062H4.16151C2.05801 0.414062 0.350006 2.26846 0.350006 4.55226V31.4487C0.350006 33.7325 2.05801 35.5869 4.16151 35.5869H30.8385C32.942 35.5869 34.65 33.7325 34.65 31.4487V4.55226C34.65 2.26846 32.942 0.414062 30.8385 0.414062ZM7.97301 2.48506C8.44901 2.48506 26.523 2.48506 27.027 2.48506V15.9333C27.027 16.5033 26.5965 16.9669 26.075 16.9669H8.92501C8.40001 16.9669 7.97301 16.5033 7.97301 15.9333V2.48506ZM32.746 31.4487C32.746 32.5925 31.8955 33.5159 30.842 33.5159H4.16151C3.10801 33.5159 2.25751 32.5925 2.25751 31.4487V4.55226C2.25751 3.40846 3.10801 2.48506 4.16151 2.48506H6.06551V16.9669C6.06551 18.1107 6.91601 19.0341 7.96951 19.0341H27.0235C28.077 19.0341 28.9275 18.1069 28.9275 16.9669V2.48506H30.8315C31.885 2.48506 32.7355 3.41226 32.7355 4.55226V31.4487H32.746Z"
fill="#11100E"
/>
<path
d="M22.2635 12.8284C22.7885 12.8284 23.2155 12.3648 23.2155 11.7948V7.65665C23.2155 7.08665 22.785 6.62305 22.2635 6.62305C21.742 6.62305 21.3115 7.08665 21.3115 7.65665V11.7948C21.3115 12.3648 21.7385 12.8284 22.2635 12.8284Z"
fill="#11100E"
/>
</svg>
);
};
export default SaveIcon;

How to use linearGradient in react-native-svg

I have some SVG graphics that I would like to apply conditional styling on (e.g. linearGradient when it's active). How would I go about achieving this? I'd rather not (if there's another way) have to go in a manually add a defs tag with linearGradients in there, and I've seen stuff about using an externals defs file to access the fill I want (so I can specify either a solid color or gradient depending on state). I'm not sure how to ask, or where to look.
An example:
An SVG file:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 26 26">
<path d="M20.94 9.56c.74 0 1.35.62 1.35 1.38v1.84c0 3.79-2.48 7.85-6.44 8.81v1.36A3.02 3.02 0 0 1 12.88 26a3.02 3.02 0 0 1-2.97-3.05v-1.34c-3.36-.83-6.2-5.05-6.2-8.83v-1.84c0-.76.6-1.38 1.35-1.38.74 0 1.34.62 1.34 1.38v1.84a6.7 6.7 0 0 0 6.6 6.79 6.7 6.7 0 0 0 6.6-6.79v-1.84c0-.76.6-1.38 1.34-1.38ZM13.08 0c2.77 0 5 2.28 5 5.09v7.44c0 2.8-2.23 5.08-5 5.08-2.76 0-5-2.28-5-5.08V5.09a5.05 5.05 0 0 1 5-5.09Z" fill-rule="evenodd"/>
</svg>
Now - I have a LOT of these, so I was hoping I could link the gradient from an external source, or use some other way to just slap a linear gradient on top of them. Is there such a way? What would be the best way to add gradients to 100+ icons without having to go in and edit each one of them? Is there a bulk editor somewhere that I don't know about?

Star Rating with SVG catering for decimal point rating

I have some code to create a star rating. I have not used SVG before and I can't figure out how to get it to do the following:
Rating is out of 5
Display ratings with decimal place ie: 4.5, 3.2, 1.1 as well as whole stars
Rated stars need to be yellow, stars remaining need to be grey
How and what do I change on the example to move the star rating left and right to get it do display the stars catering for decimals?
Fiddle example:
http://jsfiddle.net/apbuc773/10/
Code:
<svg height="210" width="500" fill="url(#g)">
<polygon points="165.000, 185.000, 188.511, 197.361, 184.021, 171.180,
203.042, 152.639,
176.756, 148.820,
165.000, 125.000,
153.244, 148.820,
126.958, 152.639,
145.979, 171.180,
141.489, 197.361,
165.000, 185.000" style="stroke: red;"/>
<linearGradient y2="0.9733" x2="1" id="g" x1="0.0167" y1="0.9833">
<stop stop-color="#F00" offset="0.4733"/>
<stop stop-color="rgb(255, 255, 255)" offset="0.5033"/>
</linearGradient>
</svg>
The code attached - is all this needed? As there will be 5 stars in total, can it be simplified.
Thanks
Here is Fiddle with dots:
http://jsfiddle.net/cnLHE/296/
You can place a rectangle underneath masked elements. In this Fiddle, the rectangle is width=90, which is 90% (at very bottom).
<rect x="0" y="0" width="90" height="20" style="fill:#2498c7; mask: url(#mask5)"/>
Change the 90 to 55, for example, and the underlying fill will shrink width.
Warning: I scrapped this method, because it did not work well with 20+ instances in page. For example, when loading a grid of rated products, the ratings graphic would sometimes disappear in Chrome. JS methods were more reliable.
You can adjust the <linearGradient> with some simple JS. Example below.
function setFraction(fraction)
{
document.getElementById("stop1").setAttribute("offset", fraction);
document.getElementById("stop2").setAttribute("offset", fraction);
}
setFraction(0.4);
<svg height="210" width="500">
<polygon points="165.000, 185.000, 188.511, 197.361, 184.021, 171.180,
203.042, 152.639,
176.756, 148.820,
165.000, 125.000,
153.244, 148.820,
126.958, 152.639,
145.979, 171.180,
141.489, 197.361,
165.000, 185.000" style="stroke:red; fill:url(#g)"/>
<linearGradient id="g" x1="0" y1="0" x2="1" y2="0">
<stop id="stop1" stop-color="#F00" offset="0.5"/>
<stop id="stop2" stop-color="#fff" offset="0.5"/>
</linearGradient>
</svg>
If you wanted to avoid JS, then you could create 11 different versions of the star (unfilled, 0.1, 0.2 ... 0.9, filled) and just include the correct one.
Change the offset fields from 0 (unfilled) to 1 (filled) to move the rating.
Not sure why you're specifying red in two different ways or why you've slightly different offset values.

SVG filter fails to render in Firefox and prevents fill attribute from being applied

I am having the weirdest problem with an svg filter and I'm not sure how to debug the problem or what the fix might be.
I have a drop shadow filter that I'm applying to a circle. Here is the SVG markup that I'm using (only showing one arc of the donut chart for brevity):
<svg height="240" width="240">
<defs>
<filter width="130%" height="130%" id="dropshadow">
<feGaussianBlur stdDeviation="1" result="blur-out" in="SourceAlpha">
</feGaussianBlur>
<feOffset result="shadow-out" dy="2" dx="1" in="blur-out">
</feOffset>
<feColorMatrix result="color-out" values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .3 0" type="matrix" in="shadow-out">
</feColorMatrix>
<feBlend mode="normal" in2="color-out" in="SourceGraphic">
</feBlend>
</filter>
</defs>
<g transform="translate(120,120)" class="donut">
<g class="arcs">
<g class="arc">
<path d="M-63.63961030678927,-63.63961030678928A90,90 0 1,1,-29.811356451234897,84.91927358696267L-27.492695393916627,78.31444119686557A83,83 0 1,0 -58.68986283848344,-58.68986283848345Z" class="a"></path>
<circle transform="translate(91.16631091370033,-20.75942567573879)" filter="url(#dropshadow)" r="17" class="a"></circle>
<text transform="translate(91.16631091370033,-20.75942567573879)" text-anchor="middle" dy=".35em" class="chart-label">30</text>
</g>
</g>
</g>
</svg>
This is how it renders in Internet Explorer, Chrome, and Firefox:
However, when I add the chart to my application which uses angularjs/bootstrap and open it up with Firefox it renders like this:
The drop shadow is no longer working and neither is the fill color for the circle. Even if I select the element and apply a fill directly, it still doesn't work. However, if I delete the filter from the circle (fill="url(#dropshadow)"), the fill color starts working again. Note that the chart renders correctly in all other browsers.
What could be causing the fill to suddenly stop working only in Firefox and only when added to my angularjs/bootstrap project?
When you re-add the filter using inline css (style="filter:...").
Does it work again then?

How do you clone a path resource in Silverlight?

I have a resource defined in my Xaml file as follows:
<Path x:Key="myPath"
Data="M14.773241,18.080208 C12.373256,18.080208 10.239936,19.30687 10.239936,27.573483
L10.239936,36.106766 C10.239936,45.440037 12.586588,46.506699 14.986573,46.506699
C18.613216,46.506699 19.359879,42.400059 19.359879,35.3601 L19.359879,27.733482
C19.359879,20.05353 17.386559,18.080208 14.773241,18.080208 z M14.879907,11.786915
C17.973221,11.786915 22.293194,13.013573 24.906511,17.920212 C26.773167,21.386856
27.519829,27.093487 27.519829,32.213455 C27.519829,34.506775 27.306496,41.706726
24.906511,46.453365 C23.626518,49.013351 20.906536,52.799992 15.199905,52.799992
C2.1333201,52.799992 2.1333201,37.600086 2.1333201,32.160122 C2.1333201,28.05348
2.1333201,22.666847 4.4266391,18.453541 C5.8666301,15.840225 8.639946,11.786915
14.879907,11.786915 z"
/>
I want to able to add multiple "instances" of this path (and several others) to a StackPanel. Of course, I can't simply add "myPath" to the panel since it's already a child of another container.
However, I can't seem to be able to clone the path either. I've tried:
Path clone = new Path()
{
Data = source.Data
};
But no luck...exception about value being out of expected range.
Finally, I tried digging into source.Data (a PathGeometry), but it contains no PathFigures...I have no idea why, since the Path does render if I copy it from the resource section to a panel directly.
What gives?
Thanks,
Sergio
Put the path data in a string resource:
<Page.Resources>
<system:String x:Key="PathData">
M14.773241,18.080208 C12.373256,18.080208 10.239936,19.30687 10.239936,27.573483
L10.239936,36.106766 C10.239936,45.440037 12.586588,46.506699 14.986573,46.506699
C18.613216,46.506699 19.359879,42.400059 19.359879,35.3601 L19.359879,27.733482
C19.359879,20.05353 17.386559,18.080208 14.773241,18.080208 z M14.879907,11.786915
C17.973221,11.786915 22.293194,13.013573 24.906511,17.920212 C26.773167,21.386856
27.519829,27.093487 27.519829,32.213455 C27.519829,34.506775 27.306496,41.706726
24.906511,46.453365 C23.626518,49.013351 20.906536,52.799992 15.199905,52.799992
C2.1333201,52.799992 2.1333201,37.600086 2.1333201,32.160122 C2.1333201,28.05348
2.1333201,22.666847 4.4266391,18.453541 C5.8666301,15.840225 8.639946,11.786915
14.879907,11.786915 z
</system:String>
</Page.Resources>
And to use it:
<Path x:Name="Path1" Data="{StaticResource PathData}" Fill="Blue" ... />
<Path x:Name="Path2" Data="{StaticResource PathData}" Fill="Red" ... />
You'll need this in your XAML declaration:
xmlns:system="clr-namespace:System;assembly=mscorlib"
If you want to create paths programmatically using a common path string, Silverlight is missing a bit of key functionality that WPF has -- so you have to kludge it:
string pathXaml =
#"<Path xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
Data=""path_data_goes_here"" />";
Path path = (Path)System.Windows.Markup.XamlReader.Load(pathXaml);

Resources