Draw custom pushpin in code without using an image - silverlight

I need to draw a pushpin for the Bing Silverlight control that can have the head be a variable color. I can draw a nice dot like this:
Dim marker As Ellipse = New Ellipse
marker.Fill = New SolidColorBrush(Color.FromArgb(255, 11, 255, 0))
marker.Stroke = New SolidColorBrush(Colors.Gray)
marker.Width = 10
marker.Height = 10
I'll be making dozens of pushpins, each with a slightly different color for the Fill. How can I add the pointy part? I would like to have some amount of flaring out at the top so that it looks more like a pushpin and less like a lollipop.
Examples in C# are welcome as well.

Maybe there's a reason you need it to be a custom one rather than using the built-in pushpin objects, but if not, you can set the background color on those pushpins like so:
myPushpin.Background = new SolidColorBrush(Colors.Gray);
As far as actually drawing your own, I'm not as sure. Could you draw some sort of a triangle?

Related

Add Markers in WPF

I need to add markers to my map. Problem: I'm using WPF, not WinForms.
GMapMarker marker = new GMapMarker(new PointLatLng(-25.966688, 32.580528));
gmap.Markers.Add(marker);
Now according to this question the solution is:
marker.Shape = new MarkerShape(....);
Could someone explain to me, how to I initalize this shape?
Thanks!
I resolved the problem with:
marker.Shape = new Ellipse
{
Width = 10,
Height = 10,
Stroke = Brushes.Black,
StrokeThickness = 1.5
};
That's a little black circle.
You have to add a new UserControl - your own, and inside the control put a image you like (for example pin image). Note that all the events (like Click event) must be implement inside a control.
After that you can add the marker like:
GMapMarker marker = new GMapMarker(new PointLatLng(##, ##));
marker.Shape = new PinControl();
gmap.Markers.Add(marker);

Animate a combined geometry along a path

I have WPF/VB application that animates an ellipse geometry along a path using point animation. I used PointAnimationUsingPath and a Storyboard as per this MSDN example and it works great.
I now want to show a number inside the ellipse. To do this I created a combined geometry and set my ellipse as geometry1. I then created a formattedtext(...).buildgeometry for my number and set that as geometry2. Like this:
Dim CarGeo AS New CombinedGeometry()
CarGeo.Geometry1 = New EllipseGeometry(StartPoint, 5, 5)
CarGeo.Geometry2 = New FormattedText(carIndex.ToString, System.Globalization.CultureInfo.GetCultureInfo("en-us"), Windows.FlowDirection.LeftToRight, New Typeface("Veranda"), 7, Brushes.White).BuildGeometry(New Point(StartPoint.X - 4, StartPoint.Y - 4))
The resulting geometry is exactly what I wanted.
The problem is I don't seem to be able to animate this geometry along my path because unlike an ellipse there is no center property in a combined geometry to set the targeted property to on the StoryBoard.
' Create a PointAnimationgUsingPath to move the car along the animation path.
cpAnimation = New PointAnimationUsingPath
cpAnimation.PathGeometry = pgSectorPath(intSector)
cpAnimation.Duration = timDuration
' Set the animation to target the Center property of the EllipseGeometry
Storyboard.SetTargetName(cpAnimation, "CarGeo")
Storyboard.SetTargetProperty(cpAnimation, New PropertyPath(EllipseGeometry.CenterProperty))
Is there I property in a combined geometry that I can use for the animation?
If not can I wrap the geometry in something else that can be animated?
I'm very new to WPF and have wasted way too much time searching for an answer to this. Any help would be greatly appreciated.
Just wrap the CombinedGeometry into a Path object, as in the MS example:
http://msdn.microsoft.com/en-us/library/system.windows.media.combinedgeometry(v=vs.110).aspx

WP7 Game - rotate only some controls when orientation changed

I'm making a simple WP7 game and I have a little problem with orientation changing. My gameboard looks like this:
And I need to rotate only the numbers when orientation changed. Is there any easy way to do it? The numbers are TextBlocks and lines are rectangles. Gameboard is Canvas (but I can use Grid as well).
Or i could exclude the canvas from automatic rotating and only redraw the numbers. But I don't know how to do it either.
Using PlaneProjection should be fine:
<TextBlock.Projection>
<PlaneProjection RotationZ="90"/>
</TextBlock.Projection>
Obviously this would apply the projection immediately, so you would need to create it in code (or try using 0 for the Z value and then changing that in code (possibility of this is a long shot)) based on the data provided (and within) the OrienationChanged event handler, such as:
myTextBlock.Projection = new PlaneProjection { RotationZ = 90 };

Drawing Basic Shapes in WPF InkCanvas

I am working on a paint like application in wpf.I want the users to be able to add some drawings over images or plain surfaces.Also i want to draw some basic shapes like line,ellipse or a rectangle.I am trying to work with an inkcanvas,where i can do freehand drawing,but i cant draw shapes like in paint.Can anyone guide me and provide some clues on how to do it.Please help me on this.Any inputs will be greatly appreciated.
There are two sorts of collections in an InkCanvas:
Strokes, which are composed of StylusPoints and defined by DrawingAttributes. That's what the Ink is, as drawn by a mouse or stylus.
The other is Children, which can contain FrameworkElements. Ellipse, for instance, is a Shape is a FrameworkElement.
Try playing around with yourCanvas.Children.Add(ellipse) and see how you go. There is certainly no reason to shy away from the InkCanvas just because you also want to use predefined shapes.
It's worth pointing out, though, that the InkCanvas's little brother, the InkPresenter, does NOT have a Children property. And Silverlight only has that one.
WPF provides a Shape class that includes prebuilt methods that you can draw shapes with. Don't use the inkcanvas and instead draw directly to a canvas.
Here http://ciintelligence.blogspot.com/2011/07/silverlight-drawing-tool-silver-draw.html
you can find better control which improved SilverDraw control with extra features:
Freatures are:
* You can draw basic shapes and also can draw using freehand pencil.
* You can erase drawing.
* You can undo and redo drawing.
* Can save drawing as jpeg in server side.
Here is a simple implementation:
public void drawCircleAp(Double EHeight, Double EWidth, InkCanvas surface)
{
Ellipse e1 = new Ellipse();
e1.Width = EWidth;
e1.Height = EHeight;
var brush = new SolidColorBrush();
brush.Color = Color.FromArgb(100, 0, 0, 0);
e1.Stroke = brush;
e1.StrokeThickness = 4;
surface.Children.Add(e1);
}

Image Flipping in WPF

How do you get an image to be reflected in wpf without using the xaml? I have a rectangle with a BitmapImageBrush as its fill. I want to be able to regularly flip this image (X-axis) back and forth at will in C#. I've read about using the ScaleTransform property but this only seems to work in the xaml and that's not what I want.
This is how the image is created:
ImageBrush l = new ImageBrush(new BitmapImage(new Uri(uriPath, UriKind.Relative)));
_animation.Add(l);
_visual = new Rectangle();
_visual.Fill = _animation[0];
_visual.Width = width;
_visual.Height = height;
_visual.Visibility = Visibility.Visible;
_window.GameCanvas.Children.Add(_visual);
_animation is a list of ImageBrushes.
This is really simple, yet I can't seem to figure out how to do it. Please help.
You can still add a scale transform programmatically, rather than using xaml.
For instance, in this article.
To do the flip, set your scale transform to be negative in the direction you want to flip (ie, if horizontal, set x to -1, or -desiredScale if you also want to resize).

Resources