Is there a way to get a control's absolute screen co-ordinates on Windows Phone? also, will help if that method will work with UserControl components. WPF seems to have Control.PointToScreen, which isb't in the WP APIs
The idea is I'm trying to use a Callout control to point to a UserControl on the screen as a help bubble, and the anchor point doesn't take in absolute coordinates either - so it's a huge connected problem which I'll build up as an answer to this post.
Use UIElement.TransformToVisual()
something like this should do the trick:
var control = this; // assign the control you want to get the position of.
var transform = control.TransformToVisual(Application.Current.RootVisual);
var controlPosition = transform.Transform(new Point(0, 0));
probably you could try Control.MousePosition instead
is this want you want (though it's for WP7): How do you find the screen position of a control in silverlight on WP7?
Related
I have a Windows Phone application with a map. On this map, there are several pushpins (different infos on the map) and a pushpin of the current position. I want to show the heading direction (the direction the user looks with his phone) on the current position pushpin (using the compass angle). I already have a custom control that rotates according to the compass value. What I don't know is how to incorporate it into the map, i.e. show it on the current position on the map.
Do you have any ideas?
Thank you very much.
PS: If you don't know what I mean, I intend to do something like it's available in the (Nokia) Here Maps .
I don't have a complete answer. What I know is you can add any control to a map using this technique:
myMap.Layers.Add(new MapLayer()
{
new MapOverlay()
{
GeoCoordinate = new GeoCoordinate(37.795032,-122.394927),
Content = new Ellipse
{
Fill = new SolidColorBrush(Colors.Red),
Width = 40,
Height = 40
}
}});
This comes from http://developer.nokia.com/Community/Wiki/What's_new_in_Windows_Phone_8
Now this will display a simple red dot, but I understand you can put just about any control in there. Use your control, bind the rotation to a value that will hold the rotation in your view model and I think you are quite done. Does this work for you?
I'm trying to create an animation similar to the AppBar - basically make a control come in from the bottom edge of the screen. The problem with this is that the height of the control can change depending on its content, so I can't set an initial TranslateTransform.Y value in the XAML or in the Loaded event because the contents get generated AFTER the page is loaded.
So, in other (and fewer) words. I need to animate a control for which I don't know its size into the screen. Any ideas?
Thanks in advance.
You can use a Transition.
E.g. PaneThemeTransition or EntranceThemeTransition.
I'm not sure which property you should use to add a transition because it depends on your case. But you can do something like this:
Popup.ChildTransitions = new TransitionCollection { new EntranceThemeTransition() };
The Popup is not mandatory:
<uielement>
<uielement.Transitions>
oneOrMoreTransitions
</uielement.Transitions>
</uielement>
Animations
I have 5 Images and a border, when the user clicks an image, I want the border to slide over until it is directly over the Image that was clicked.
I am having a hard time figuring out this transform stuff. I am good with C# but new to wpf. I am quite certain that the translatetransform is what I need, but I have no idea how to implement it. Can someone show me, or point me to a good tutorial on this topic.
var RT=new TranslateTransform(90,0);
SelectBorder.RenderTransform = RT;
SelectBorder.BeginAnimation(...//I don't know what a dependency object is
I would recommend reading the documentation, it has a full example of how to use the method. (Also you would start the animation on the transform not the Border)
How would I draw something on a Canvas in C# for Windows Phone?
Okay, let me be a little more clear.
Say the user taps his finger down at 386,43 on the canvas. (the canvas is 768 by 480)
I would like my application to be able to respond by placing a red dot at 386,43 on the canvas.
I have no prior experience with Canvas whatsoever.
If this is too complex to be answered in one question (which it probably is), please give me links to other websites with Canvas and Drawing articles.
There are various ways of doing this. Depending on the nature of the red dot, you could make it a UserControl. For a basic circle, you can simply handle your canvas' ManipulationStarted event.
private void myCanvas_ManipulationStarted(object sender, ManipulationStartedEventArgs e)
{
Ellipse el = new Ellipse();
el.Width = 10;
el.Height = 10;
el.Fill = new SolidColorBrush(Colors.Red);
Canvas.SetLeft(el, e.ManipulationOrigin.X);
Canvas.SetTop(el, e.ManipulationOrigin.Y);
myCanvas.Children.Add(el);
}
I think you need to approach the problem differently. (I'm not including code on purpose, because of that).
Forms and controls in an Windows applications (including Phone) can be refreshed for several reasons, at any time. If you draw on a canvas in response to a touch action, you have an updated canvas until the next refresh. If a refresh occurs the canvas repaints itself, you end up with a blank canvas.
I have no idea what your end goal is, but you likely want to either keep track of what the user has done and store that state somewhere and show it in a canvas on the repaint of the canvas. This could be done with storing all the actions and "replaying" them on the canvas, or simply storing the view of the canvas as a bitmap and reload the canvas with that bitmap when refreshed. But, in the later case I think using a canvas isn't the right solution.
I would like to rotate the content of a Form (WinForms). Is it possible to implement that behavior in some way?
I already known that with WPF would be easier but the form and the logic are already implemented and in addition I should work with Framework 2.0.
I also known that using video card features that would probably possible, but I need to rotate only one specific form, not all applications running on the target pc.
If you draw the content by yourself using OnPaint, you can use Graphics.Transform and feed it a rotation matrix or use Graphics.RotateTransform(float angle).
Be aware that this will not be perfect though. Some things might not rotate as expected such as text and images.
Basicly You cant do this. There are two possible way to solve the problem
Find third party controls, which can be rotated
Rewrite all controls. You should ovveride paint method of ALL controls you want to rotate, so they will owner drawed.
Can you create a wpf window with a WindowsFormHost holding your content and then apply a rotation transform to it?
At the end I solved this by cloning the form and all the controls that contains (if someone want to take a look the code just comment) and proceed to rotate them one by one.
Private Shared Sub RotateForm180(frm As Form)
For Each ctrl As Control In frm.Controls
RotateControl180(ctrl)
Next
End Sub
Private Shared Sub RotateControl180(ctrl As Control)
Dim oScreenRect As Rectangle = ctrl.Parent.RectangleToScreen(ctrl.Parent.ClientRectangle)
ctrl.Location = New Point(oScreenRect.Width - (ctrl.Location.X + ctrl.Width),
oScreenRect.Height - (ctrl.Location.Y + ctrl.Height))
For Each c As Control In ctrl.Controls
RotateControl180(c)
Next
End Sub
Form background can also by rotated.
_BackgroundImage.RotateFlip(RotateFlipType.Rotate180FlipNone)