wpf toolkit rating size - wpf

I'm using a rating control (from wpf toolkit) in my application. Is there any way I can scale this control? The rating stars are too big for my application..
I tried setting the height or width but that just cuts the stars but doens't resize them:
Rating ratingControl = new Rating();
ratingControl .ItemsSource = ratingItems;
ratingControl.Width = 50;
ratingControl.Height = 10;
// --> this doesn't change the size of the stars
Greets Daan

i dont know the rating control, but if you wanna scale something in wpf you can simply use ScaleTransform
<Rating>
<Rating.LayoutTransform>
<ScaleTransform ScaleX="0.8" ScaleY="0.8"></ScaleTransform>
</Rating.LayoutTransform>
</Rating>

Related

form size to different resolutions

hoping you could help me out with the sizing if my forms. on my school laptop the form fits nicely to the resolution. however, on my personal laptop, the form does not fit the larger res and for some reason is more zoomed. I have sent pictures too
You get you screen resolution with following code:
Screen.PrimaryScreen.Bounds.Width;
Screen.PrimaryScreen.Bounds.Height;
you could adjust the position from every control in the form_load event with Control.Location or the size with Control.Size depending on the width and height of your screen.
For example
label1.Location.X = Screen.PrimaryScreen.Bounds.Width - 100;
label1.Location.Y = Screen.PrimaryScreen.Bounds.Height - 50;
If you want your control to always be fullscreen, you could also add this.WindowState = FormWindowState.Maximized; in the form_load event. then its easier to adjust the positions of the controls depending on screen size.

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);

Dynamic canvas content to fit to canvas in c# on clicking of fit to screen button in wpf

I have a canvas which is in scrollviewer. This canvas is a dynamic canvas on which many other controls can be dropped. The scrollviewer will be shown when controls are dragged & dropped out of canvas regions ie., right and bottom.
I have implemented the code for zoom in and zoom out of the canvas which works fine, but failed to find the code to implement fitting dynamic canvas content to the actual canvas size.
I'm looking for something to automatically fit the canvas content to its size, ie calculate the zoomscale as to fit the content to the canvas size.
This is a complicated one.
You should work with some properties of the ScrollViewer to get the desired result: ContentHorizontalOffset, ContentVerticalOffset, ViewportWidth, ViewportHeight (among others existing in the component..)
Here is a snippet of code that helped me:
Point realSize = new Point(this.canvasAreas.ActualHeight, this.canvasAreas.ActualWidth);
Point sizeAvailable = new Point(this.scroolMain.ActualHeight, this.scroolMain.ActualWidth);
double scaleX = sizeAvailable.X / realSize.X;
double scaleY = sizeAvailable.Y / realSize.Y;
double newScale = Math.Round(Math.Min(scaleX, scaleY), 2);
this.gridScaleZoom.ScaleX = newScale;
this.gridScaleZoom.ScaleY = newScale;
There are several articles on CodeProject and looking on google that can assist you in working with ScrollViewer zoom.
Although most are complicated and complex. Hope this helps you a bit.
Here is my xaml code:
and on Button click I would like to scale accordingly.I have tried the below code.
Point realSize = new Point(this.formCanvas.ActualHeight, this.formCanvas.ActualWidth);
Point sizeAvailable = new Point(this.myScrollViewer.ActualHeight, this.myScrollViewer.ActualWidth);
double scaleX = sizeAvailable.X / realSize.X;
double scaleY = sizeAvailable.Y / realSize.Y;
double newScale = Math.Round(Math.Min(scaleX, scaleY), 2);
this.canvasScale.ScaleX = newScale;
this.canvasScale.ScaleY = newScale;
It also results the same.
Please correct the code if it is incorrect.

Rendering Two rectangles in a canvas in silverlight

I have added canvas in the xaml file. From code iam creating two rectangles and adding it to the canvas. Here the size of both the triangles are same. When I run the application both the triangles are coming one upon the other I mean they are overlapping. But when I add them to a Stack panel they are coming one after the other?
Can anyone tell me how can I render two rectangles in my example one after the other without overlapping each other using Canvas?
Here is the sample code of my app;
Rectangle rect1 = new Rectangle();
rect1.Margin = new Thickness(1.5, 2, 1, 1);
rect1.Height = 40;
rect1.Width = 60;
rect1.Stroke = new SolidColorBrush(Colors.Black);
myCanvas1.Children.Add(rect1);
Rectangle rect2 = new Rectangle();
rect2.Height = 40;
rect2.Width = 60;
rect2.Stroke = new SolidColorBrush(Colors.Black);
myCanvas1.Children.Add(rect2);
Thanks in advance
Padma
A StackPanel arranges its Child elements automatically so that they don't overlap. A Canvas doesn't, as it arranges its Child elements according to their Canvas.Left and Canvas.Top attached properties.
Assign your Rectangles those properties to arrange them manually how you like.

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