I am making an application in Silverlight. In that application I want to draw a circle at runtime using coordinates. I have drawn the circle dynamically but I want to that circle at specific co-ordinates(X,Y). But I am not getting that.
Please help me. Thanks in advance.
Ellipse ellipse = new Ellipse() { Width = 150, Height = 150, Stroke = new SolidColorBrush(Colors.Black),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
ellipse.SetValue(Grid.RowProperty, 0);
ellipse.SetValue(Grid.ColumnProperty, 0);
this.LayoutRoot.Children.Add(ellipse);
TextBlock textblock = new TextBlock() { Text = "Hello", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
textblock.SetValue(Grid.ColumnProperty, 0);
textblock.SetValue(Grid.RowProperty, 0);
this.LayoutRoot.Children.Add(textblock);
And have a look in below sites.....
http://pietschsoft.com/post/2010/06/28/Silverlight-Bing-Maps-Draw-Circle-Around-Latitude-Longitude-Location.aspx
http://www.kunal-chowdhury.com/2011/07/how-to-create-circular-loader-using.html
HOpe this post will help you to solve your problem... If so please mark it answer...
To achieve this, use a canvas container and set the Canvas.Left and Canvas.Top attributes on the ellipse. See http://msdn.microsoft.com/en-us/library/system.windows.controls.canvas.left(v=vs.95).aspx (and the corresponding Canvas.Top article) for more information.
Related
I want to set my StackPanel Orientation property to vertical in code behind. I cant find Enum that I can set Vertical.
var panel = new StackPanel();
panel.Orientation = Vertical;
After some research I found from MSDN
var panel = new StackPanel();
panel.Orientation = Orientation.Vertical;
May be helpful for researchers
I am working with WPF DrawingVisual and Pen and encountered a problem.
When I draw a DrawingVisual with Pen, say, a Rectangle as follows:
Pen StrokePen = new Pen();
StrokePen.Brush = Brushes.SkyBlue;
StrokePen.Thickness = 6;
DrawingVisual dv = new DrawingVisual
DrawingContext dc = dv.RenderOpen();
dc.DrawingRectangle(......., StrokePen, ......);
dc.Close();
I found that the half of the Stroke cover the rectangle like the following:
Therefore, if the Thickness of the Pen is too large so that it even larger than the Rectangle, the Rectangle will disappear (The whole rectangle is covered by the Stroke).
Could I adjust some setting so that the Stroke (Pen) drawn on the rectangle will not cover the rectangle (only draw beyond the sides of the rectangle)
Thank you.
You could simply draw the Rectangle twice, first with a Pen, then with a Brush:
using (DrawingContext dc = dv.RenderOpen())
{
...
dc.DrawingRectangle(null, StrokePen, ...);
dc.DrawingRectangle(FillBrush, null, ...);
....
}
In wpf border of rectangle is its internal content so no there is no way to force it to be outside of rectangle. But you can adjust size of your rectangle to compensate for Pen.Thickness.
I'm trying to take a screenshot of a datagrid which has to many rows to be displayed. So there is a scrollviewer.
So when I just put the datagrid into the Render Method of RenderTargetBitmap I obviously just get the viewable part of the datagrid.
I read that one can take a screenshot of a content when actually rendering the ItemsPresenter of the ScrollViewer of that control, as the ItemsPresenter would have the "real" Width and Height of the content.
Unfortunatly my ScrollViewer doesnt have any different Height, ActualHeight or RenderSize.Height than the dataGrid.
So I always just get the visible part of the Content.
Anyone know how to do this the right way, that it actually takes the whole content ?
Code:
var scroll = GetTemplateChildByName(dataGridInOut);
if (scroll != null)
{
var item = scroll.Content as ItemsPresenter;
var width = item.RenderSize.Width;
var height = item.RenderSize.Height;
var rtb = new RenderTargetBitmap((int) Math.Round(width), (int)Math.Round(height), 96, 96,
PixelFormats.Pbgra32);
var drawingVisual = new DrawingVisual();
var visualBrush = new VisualBrush(item);
using (var context = drawingVisual.RenderOpen())
{
context.DrawRectangle(visualBrush, null, new Rect(new Point(0,0), new Size(width, height)));
}
rtb.Render(drawingVisual);
Clipboard.SetImage(rtb);
}
Leaf is right. You could instantiate another DataGrid bound to the same source programmatically, put it into a container which gives it infinite space, wait for it to render and then take a screenshot of this. No need to actually show it in the UI.
I have content presenter with contented bound to a shape from the templated parent. When the shape is an ellipse, the content presenter shows the ellipse, however when I change the Shape to path and set the data property to ellipse geometry nothing gets displayed, I am setting the stroke and fill same as on the ellipse shape. Here is how I am constructing the path:
Shape = new Path();
Shape.Data = new EllipseGeometry();
Shape.Fill = Brushes.Transparent;
Shape.Stroke = Brushes.CadetBlue;
However when I replace it with this it does work (Assuming Shape is of type Ellipse):
Shape = new Ellipse();
Shape.Fill = Brushes.Transparent;
Shape.Stroke = Brushes.CadetBlue;
The reason why I want to use a path with a geometry as data, is because I want to test intersection on the shape, but I don't know how to get the geometry of a shape object, where as if the shape is of type Path I can test against Shape.Data.
Any help would be appreciated.
The EllipseGeometry behaves a bit differently to the Ellipse shape. Its dimensions are defined by its RadiusX and RadiusY properties, which by default are 0, thus nothing is drawn. You can set these as follows:
Shape.Data = new EllipseGeometry { RadiusX = 1.0, RadiusY = 1.0 };
However, this still probably won't display as your Ellipse does. The Ellipse also defaults to Stretch.Fill for its Stretch property, but the Path has Stretch.None. If you change this, they should look the same:
Shape.Stretch = Stretch.Fill;
You can play around with the other properties of the Path and the EllipseGeometry to size, orient, and locate it correctly.
I have a scrollviewer with dynamic content. On an event, a new content is made visible and the scrollbar appears. How do i make it auto scroll to have that content in view?
Thanks,
Shawn Mclean
Use ScrollToVerticalOffset() to do this, passing in the coordinates of the new content.
var newContent = GetNewContent();
var generalTransform = newContent.TransformToVisual(
Application.Current.RootVisual as UIElement);
Point offset = generalTransform.Transform(new Point(0, 0));
double controlTop = offset.Y;
double controlLeft = offset.X;
scrollViewer.ScrollToVerticalOffSet(controlTop);
scrollViewer.ScrollToHorizontalOffSet(controlLeft);
Are you sure Scrollviewer is the control you need here?
Sounds to me like you ought to be using ListBox (which you can heavily style if necessary). It has a ScrollIntoView(item) method which would acheive your goal.