My WPF application supports zooming. When I show icons on a canvas, and I zoom in, all the shapes, text, etc. are shown correctly, but the icons are shown pixelelated.
What is the correct way to show icons?
I was thinking about building the icons in a vectorial format, and then convert them to XAML?
Is this the correct way?
How should I proceed?
Could you please give an example about how to use it?
You can use ScaleTransform on your icons like.
var st = (ScaleTransform)image.RenderTransform;
double zoom = e.Delta > 0 ? .2 : -.2;
st.ScaleX += zoom;
st.ScaleY += zoom;
Related
How to remove the left margin of a Microsoft Chart Control (Shown as a red rectangle)?
The chart control is docked in the parent form. It seems that this margin is dynamic and depends on the chart width.
I cannot find such an option. Do I need to work with ChartArea location?
This is a .NET C#, WinForms application.
The following code worked for me:
Chart1.ChartAreas[0].Position.X = 0;
If you want to remove all the paddings:
Chart1.ChartAreas[0].Position.X = 0;
Chart1.ChartAreas[0].Position.Width = 100;
Chart1.ChartAreas[0].Position.Height = 100;
Chart1.ChartAreas[0].Position.Y = 0;
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>
I have a rectangle on canvas. I can already moving this object using with mouse, but I can't find how can I resize it in runtime using mouse too?
And second question, how can I programatically check positions of each objects (e.g rectangles) on the canvas?
Most people use a Thumb. This is an msdn article that shows you how to use a thumb to resize a canvas. The same principles can be applied to your rectangle.
Re-sizing a rectangle using the mouse can be pretty involved. Basically you can listen for mouse-down, mouse-up, and mouse-move events which would allow you to adjust the width and height of it programmatically.
To move a rectangle within the canvas, try the following concept:
double x = Canvas.GetLeft(this.myRectangle);
x += 100;
Canvas.SetLeft(this.myRectangle, x);
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);
}
How to set the Height and width of a WPF application on maximise?
Problem I face is because of variable height of the windows taskbar in different computers
Presently, I am doing it like this. Please suggest any better technique
if (this.WindowState == WindowState.Maximized)
{
this.Height = primaryScreenHeight - 10 - System.Windows.Forms.SystemInformation.SizingBorderWidth;
this.Width = primaryScreenWidth + 2 * System.Windows.Forms.SystemInformation.FrameBorderSize.Width;
}
You dont need to do this. If you use a Grid as your layout container, objects within will always expand to use up all the space. Then you can use Margins to arrange sub-panels. Using the various HorizontalAlignment values of Left,Center,Right,Stretch and VerticalAlignment values of Top, Center, Bottom, Stretch, you can make pretty much any scalable layout without having to check if the app is maximized/minimized, etc.
Is there are a particular layout you want to achieve that perhaps I can post an example for?