Quick easy points for anyone who knows the answer:
The following Xaml path works fine in WPF but crashes in Silverlight. I can verify this behaviour in Kaxaml.
The path code is
<Path Fill="#FFEDEDED" StrokeThickness="1" Stroke="#FFA3A3A3" Opacity="0.7"
VerticalAlignment="Center" HorizontalAlignment="Center" >
<Path.Data>
<PathGeometry Figures="m 1 2 l 4.0525 5.2361 l 4.0527 -5.2361 z "/>
</Path.Data>
</Path>
The exception is a script error
Unhandled error in Silverlight Application. Failed to create a
System.Windows.Media.PathFigureCollection from the text 'm 1 2 l
4.0525 5.2361 l 4.0527 -5.2361 z'
Its supposed to draw a triangle like so:
Any ideas?
Unlike WPF Silverlight does not support converting a string to Figures.
I got the following underline/hover error message in Expression Blend:
The equivalent triangle, authored via Blend, for Silverlight is:
<Path Fill="#FFEDEDED" StrokeThickness="1" Stroke="#FFA3A3A3" Opacity="0.7"
VerticalAlignment="Center" HorizontalAlignment="Center"
Data="m 1 2 l 4.0525 5.2361 l 4.0527 -5.2361 z" />
Related
If I have a rather meandering Path in my WPF app, is there a way I can make it appear as two differently-colored Paths of identical widths side-by-side? I'd rather not try to hand-code the whole thing again with slightly different values. I thought of using a Brush, but the list of Brushes doesn't appear to have one such.
Edit: I want a Path divided sharply by color, even if it curves, like this:
Made a little search, and found that also :
Two-color Path object
Timwi answer :
<StackPanel Orientation="Horizontal">
<StackPanel.LayoutTransform>
<ScaleTransform CenterX="0" CenterY="0" ScaleX="15" ScaleY="15" />
</StackPanel.LayoutTransform>
<Grid Margin="-5,0,0,0">
<Path Fill="Blue" Stroke="Transparent">
<Path.Data>
<PathGeometry>M10,10 C20,10 10,20 20,20 L20,19 C11,19 21,9 10,9</PathGeometry>
<!-- |← original path →| |← generated part →| -->
</Path.Data>
</Path>
<Path Fill="Red" Stroke="Transparent">
<Path.Data>
<PathGeometry>M10,10 C20,10 10,20 20,20 L20,21 C9,21 19,11 10,11</PathGeometry>
<!-- |← original path →| |← generated part →| -->
</Path.Data>
</Path>
</Grid>
</StackPanel>
So "playing" with margin may be much easier that the other options I told you about for what you need.
DropShadowEffect solved my issue.
I have an icon created with canvas and path. I can reuse this icon, but how can I change the color of the icon from "outside" (i.e. from view)
<Canvas x:Key="MyIcon" Width="40.000" Height="23.889">
<!-- Layer 1/<Group>/<Compound Path> -->
<Path Fill="#ffffffff" Data="F1 M 36.074,14.516 C 36.117,10.711 33.078,7.540 29.332,7.478 Z"/>
<!-- Layer 1/<Group>/<Compound Path> -->
<Path Fill="#ffffffff" Data="F1 M 35.848,2.368 C 36.766,3.651 37.097,3.832 38.095,3.558 C 38.345,3.489 38.523,3.159 38.735,2.950 C 38.499,2.756 38.281,2.426 38.025,2.395 Z"/>
<!-- Layer 1/<Group>/<Path> -->
<Path Fill="#ffffffff" Data="F1 M 35.307,14.487 C 35.268,17.908 32.499,20.618 29.098,20.563 C 25.615,20.506 22.916,17.747 22.947,14.274 Z"/>
</Canvas>
With this icon, it will always be white. What changes I can make so I will be able to change the color from xaml? For example now I show the icon like this:
<ContentControl Content="{StaticResource MyIcon}" />
I'm assuming to change the color the syntax will look something like this:
<ContentControl Content="{StaticResource MyIcon}" Color={StaticResource BlueBrush} />
Turn the Canvas into a Geometry resource by concatening the Data strings of the three Paths:
<Geometry x:Key="MyIcon">F1 M 36.074,14.516 C 36.117,10.711 33.078,7.540 29.332,7.478 Z M 35.848,2.368 C 36.766,3.651 37.097,3.832 38.095,3.558 C 38.345,3.489 38.523,3.159 38.735,2.950 C 38.499,2.756 38.281,2.426 38.025,2.395 Z M 35.307,14.487 C 35.268,17.908 32.499,20.618 29.098,20.563 C 25.615,20.506 22.916,17.747 22.947,14.274 Z</Geometry>
The use that resource with a single Path element instead of a ContentControl:
<Path Data="{StaticResource MyIcon}" Fill="Blue"/>
How to draw plus and minus signs in using data property in Path object.
This is my triangle path object. I need to change it to plus symbol.
<Path x:Name="trianglePath" Data="M 0 8 H 12 V 15 Z"/>
Here, I've created a plus and minus sign which is 10 x 10 pixels using XAML path markup syntax:
<Path Margin="10" Stroke="White" Data="M0,5 H10 M5,5 V10Z" StrokeThickness="2" Height="10" Width="10" />
<Path Margin="10" Stroke="White" Data="M0,5 H10" StrokeThickness="2" Height="10" Width="10" />
When experimenting with designing your path drawing, it's helpful to set the path element's height & width first. To better understand XAML path markup syntax, see MSDN.
You might find it easier if you draw them out on a piece of graph paper and then label the vertices with the values needed to reach it from the previous one.
Then copy this into your code.
I have the following path. The data is from some data file:
<Path StrokeThickness="5" Stroke="Black" Fill="Yellow" Data="M 30330.8847248349,-37724.909002528 L 28556.3829935257,-37596.5557453925 28031.7660050946,-38008.0608378072 27746.4689258268,-38895.6687979239 27655.7148993139,-39397.1764657993 27718.5888966473,-39755.4955438608 27628.0246979519,-40621.440862981 28514.7500540091,-41208.8847446069 29093.8320242864,-40459.5872073251 29768.3831435369,-40107.7166927063 30092.4525793664,-39483.6045857995 30784.2658266352,-38627.7070622611 30811.846313938,-38537.1499823241 30358.6906348136,-37734.2759127391 30330.8847248349,-37724.909002528" />
I like to know what this looks like, so I want to render it in Kaxaml or XamlPad. Is there an easy way to resize this path so it will render nicely centered on the screen?
Just set the path's stretch attribute to Uniform to maitain the apsect ratio and you should be able to see it in KaXaml
<Path Stretch="Uniform" StrokeThickness="5" Stroke="Black" Fill="Yellow" Data="M 30330.8847248349,-37724.909002528 L 28556.3829935257,-37596.5557453925 28031.7660050946,-38008.0608378072 27746.4689258268,-38895.6687979239 27655.7148993139,-39397.1764657993 27718.5888966473,-39755.4955438608 27628.0246979519,-40621.440862981 28514.7500540091,-41208.8847446069 29093.8320242864,-40459.5872073251 29768.3831435369,-40107.7166927063 30092.4525793664,-39483.6045857995 30784.2658266352,-38627.7070622611 30811.846313938,-38537.1499823241 30358.6906348136,-37734.2759127391 30330.8847248349,-37724.909002528" />
I want to create some up and down buttons using the standard button
background but with black arrows.
What is the best way to accomplish this with WPF??
Malcolm
I find Marlett (a font built into Windows) handy for that sort of thing.
<Button FontFamily="Marlett" FontSize="20" Content="5"/>
<Button FontFamily="Marlett" FontSize="20" Content="6"/>
Output:
No discussion on this subject would be complete without mentioning the geometry mini-language (or Path Markup Syntax) for a more compact shape definition:-
<Button>
<Path Fill="Black" Data="M 0 6 L 12 6 L 6 0 Z"/>
</Button>
<Button>
<Path Fill="Black" Data="M 0 0 L 6 6 L 12 0 Z"/>
</Button>
The first describes a Move to 0,6 Line to 12,6 Line to 6,0 and then close the shape (Z).
There is also a curve syntax.
The preferred way to do this now is using Segoe UI Symbol. It replaces Marlett and provides many useful glyphs.
Up and down would be
<Button FontFamily="Segoe UI Symbol" Content=""/>
<Button FontFamily="Segoe UI Symbol" Content=""/>
Which renders as:
This font is pre-installed on all versions of Windows 7 and 8.
As of the release of Windows 10, the Segoe UI Symbol font is considered a legacy resource and should be replaced by Segoe MDL2 Assets in all new projects as outlined here.
You can create a Polygon which represents your up and down triangles and then set them to be the content of the buttons:
<Button>
<Polygon
Points="300,200 450,200 375,300 300,200"
Stroke="Black">
<Polygon.Fill>
<SolidColorBrush Color="Black" />
</Polygon.Fill>
</Polygon>
</Button>
You can tweak these to draw different figured, but that's generally the XAML you would use for basic geometry.
If you would like to have an arrow with base rectangle you can use this sample...
<Button >
<Polygon Stretch="Fill" Fill="Black" Points="0,0 0,30 0,10 30,10 30,-10 45,10 30,30 30,20 0,20 0,0 30,0 30,10 0,10" />
</Button>