Zoom for WP7 app - c#

I'm lookin for a control for a WP7 app that allows zooming by pinch. I saw on codeplex smth like DeepZoomContener but is doesn't do well. Any ideas? I just need zoom to 150% by pinching that's all.
Regards.

Thx Mick but this messed up with my layout a bit. I did something more simple.
I use the Silverlight Toolkit for WP7 and add the pinch GetureListener to my grid
<toolkit:GestureService.GestureListener>
<toolkit:GestureListener PinchDelta="GestureListener_PinchDelta" />
</toolkit:GestureService.GestureListener>
and code in event
private void GestureListener_PinchDelta(object sender, PinchGestureEventArgs e)
{
if (e.DistanceRatio < 1.0 || e.DistanceRatio > 1.4)
{
return;
}
// Create the animation for pinch
Storyboard storyboard = new Storyboard();
DoubleAnimation pinchXAnimation = new DoubleAnimation();
pinchXAnimation.To = e.DistanceRatio;
pinchXAnimation.Duration = TimeSpan.FromSeconds(0.3);
storyboard.Children.Add(pinchXAnimation);
Storyboard.SetTargetProperty(pinchXAnimation, new PropertyPath("GridScaling.ScaleX"));
Storyboard.SetTarget(pinchXAnimation, GridScaling);
DoubleAnimation pinchYAnimation = new DoubleAnimation();
pinchYAnimation.To = e.DistanceRatio;
pinchYAnimation.Duration = TimeSpan.FromSeconds(0.3);
storyboard.Children.Add(pinchYAnimation);
Storyboard.SetTargetProperty(pinchYAnimation, new PropertyPath("GridScaling.ScaleY"));
Storyboard.SetTarget(pinchYAnimation, GridScaling);
storyboard.Begin();
}

Checkout Laurent Bugnions control.
MultiTouch Behavior for Windows Phone 7
MultiTouch Behavior: Update for Windows Phone 7 tools beta

Related

c# uwp animation make text flicker

I am creating a marquee animation for textblock. I have managed to do it with doubleanimation moving textblocks on canvas. But the problem is that text is flickering while moving each 0,5 seconds...
Here is the sample code I am using:
sb1 = new Storyboard();
DoubleAnimationUsingKeyFrames animationKeyFrames = new DoubleAnimationUsingKeyFrames();
var keyFrameStart = new EasingDoubleKeyFrame();
keyFrameStart.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0));
keyFrameStart.Value = TextWidth;
var keyFrameEnd = new EasingDoubleKeyFrame();
keyFrameEnd.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(10000));
keyFrameEnd.Value = -TextWidth;
animationKeyFrames.KeyFrames.Add(keyFrameStart);
animationKeyFrames.KeyFrames.Add(keyFrameEnd);
Storyboard.SetTargetProperty(animationKeyFrames, "(Canvas.Left)");
Storyboard.SetTarget(animationKeyFrames, textBlock1);
sb1.RepeatBehavior = RepeatBehavior.Forever;
sb1.Children.Add(animationKeyFrames);
sb1.Begin();
Does anyone knows any property, some double buffer or something like that to override this problem?
Actually, this issue was more related to device performance. I've checked your code, there's no problem in your code.
I tested your code on different configuration of the machines. The "flicker" phenomenon was different.
There's a workaround for you to alleviate this issue.
You could alleviate this issue by setting more large duration (e.g, keyFrameEnd.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(20000));).

Correct Property Path for Width-Animation in Windows Store Apps (Windows 8.1 and above)

I don't understand why my Canvas.Left and Canvas.Top Animations are running, but my Width and Height Animations are not.
Here is one example of perfectly working code:
DoubleAnimation doubleAnimationCanvasLeft = new DoubleAnimation();
doubleAnimationCanvasLeft.From = Canvas.GetLeft(aDiceToBeChecked.myGrid);
doubleAnimationCanvasLeft.To = Canvas.GetLeft(aDiceToBeChecked.myGrid) - 102;
doubleAnimationCanvasLeft.Duration = TimeSpan.FromMilliseconds(myTimespan);
doubleAnimationCanvasLeft.FillBehavior = FillBehavior.HoldEnd;
Storyboard storyboardCanvasLeft = new Storyboard();
storyboardCanvasLeft.Children.Add(doubleAnimationCanvasLeft);
Storyboard.SetTarget(storyboardCanvasLeft, aDiceToBeChecked.myGrid);
Storyboard.SetTargetProperty(storyboardCanvasLeft, "(Canvas.Left)");
storyboardCanvasLeft.Begin();
And the same for width does not work:
DoubleAnimation doubleAnimationGridWidth = new DoubleAnimation();
doubleAnimationGridWidth.From = 200.0;
doubleAnimationGridWidth.To = 304.0;
doubleAnimationGridWidth.Duration = TimeSpan.FromMilliseconds(myTimespan);
doubleAnimationGridWidth.FillBehavior = FillBehavior.HoldEnd;
Storyboard storyboardGridWidth = new Storyboard();
storyboardGridWidth.Children.Add(doubleAnimationGridWidth);
Storyboard.SetTarget(storyboardGridWidth, aDiceToBeChecked.myGrid);
Storyboard.SetTargetProperty(storyboardGridWidth, "(Width)");
storyboardGridWidth.Begin();
It does not work with Width, (Width), (UIElement.Width), (Grid.Width) and I am really not sure how to get the correct Property Path of if the Property Path is even the problem!? Could you help me?
I am using Net Version 4.5.1 and Visual Studio Express 2013 and developing for Windows 8.1 and Windows 10.
I found the missing piece:
doubleAnimationGridWidth.EnableDependentAnimation = true;
If someone else is reading this: This means this animation is using more ressources of the UI Thread. There is more information on the Microsoft-Website.
Still, if someone could tell me how to build and or debug these property paths...

Webcam - Camera Preview rotates wrong way

I would like your help please on a WebCamera problem. I've used a library available from Nuget; WebEye.Controls.Wpf.WebCameraControl (version 1.0.0). The URL is https://www.nuget.org/packages/WebEye.Controls.Wpf.WebCameraControl/
The article and instructions are available at: http://www.codeproject.com/Articles/330177/Yet-another-Web-Camera-control
Due to project constraints, I developed a WPF application for a Linx tablet (Windows 10), rather than as a Universal Windows Application. I used the WebEye library to connect to the webcam on the tablet and take pictures with it. It works fine when I hold the tablet in landscape, but not when I hold the tablet in portrait mode. In portrait mode, the CameraPreview/VideoWindow automatically rotates -90 degrees.
I tried resolve the problem to no avail.
Rotate the control surrounding the video window via the Webcamera RenderTransform or LayoutTransform property – The control rotates but the video image does not rotate correctly.
Tried to rotate the VideoWindow inside the WebCamera Content property - I got the source code from the GitHub and set the VideoWindow available for access. Recompled the library and used it to rotate the VideoWindow via its RenderTransform property. https://github.com/jacobbo/WebEye/tree/master/WebCameraControl
No matter what I do, the camera preview is always -90 degrees.
The library is simple and it does not have many properties to manipulate the video window.
The webcontrol is in XAML.
<wpf:WebCameraControl x:Name="webCameraControl"
MouseDoubleClick="webCameraControl_MouseDoubleClick"
StylusButtonUp="webCameraControl_StylusButtonUp"
MouseUp="webCameraControl_MouseUp"
TouchUp="webCameraControl_TouchUp"
GotMouseCapture="webCameraControl_GotMouseCapture"
/>
This is how I initialised the WebCamera. When the UserControl is loaded, it will then automatically connect to the webcam on the tablet. See startViewing() function.
private WebCameraId _cameraID = null;
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
startViewing();
}
private void startViewing()
{
List<WebCameraId> cams = (List<WebCameraId>)webCameraControl.GetVideoCaptureDevices();
if (cams.Count > 0)
{
_cameraID = (WebCameraId)cams[0];
webCameraControl.StartCapture(_cameraID);
}
}
I tried to force the control to rotate it correctly when the app detects a change in the Display screen. See DisplaySettingsChanged event.
public ucWebCam()
{
InitializeComponent();
Microsoft.Win32.SystemEvents.DisplaySettingsChanged += SystemEvents_DisplaySettingsChanged;
}
private void SystemEvents_DisplaySettingsChanged(object sender, EventArgs e)
{
try
{
double angle = 0;
if (SystemParameters.PrimaryScreenWidth > SystemParameters.PrimaryScreenHeight)
{
angle = 0;
}
else
{
angle = -90;
}
webCameraControl.StopCapture();
adjustWebcamAngle(angle);
webCameraControl.StartCapture(_cameraID);
}
catch (Exception ex)
{
}
}
private void adjustWebcamAngle(double angle)
{
try
{
// IGNORE portrait boolean flag
bool portrait = false;
if (angle == 90 || angle == 180)
{
portrait = true;
}
// TRIED TO SET THE ANGLE OF THE CONTROL TO NO AVAIL
RotateTransform rotTransform = new RotateTransform(angle);
//rotTransform.Angle = angle;
ScaleTransform scaleTransform = new ScaleTransform();
//scaleTransform.ScaleX = (portrait) ? 0 : 1;
//scaleTransform.ScaleY = (portrait) ? 0 : 1;
TransformGroup tGroup = new TransformGroup();
//tGroup.Children.Add(scaleTransform);
tGroup.Children.Add(rotTransform);
// ROTATE CAMERA!
webCameraControl.RenderTransform = tGroup;
} catch (Exception ex)
{
}
}
So far I only rotated the WebCam control, not the video image.
I looked through the comments in Alexander's article with no joy at: http://www.codeproject.com/Articles/330177/Yet-another-Web-Camera-control
How can I rotate the Camera preview correctly? Can you please advise where I'm going wrong?
I have attached two images to illustrate my problem.
In case you are not a stranger to C#, I would recommend you use the EMGUCV nuget and create your own preview application. It`s not that hard, and you could use MVVM to bind the frames to your View, making it better than using code behind your control.
PS: This is not an answer, but it is a solution to your problem. I cannot not post comments yet, as I do not have 50 points :(
Have a nice day.

Animate on an X C# NOT XAML Margin Animation Windows 8

Can anyone explain to me what I am doing wrong here? I am most certainly a beginner at C# and I do not want to leave it up to XAML when it comes to animating this image on the screen.
_sb = new Storyboard();
DoubleAnimation moveXAnim = new DoubleAnimation();
moveXAnim.Duration = TimeSpan.FromMilliseconds(5000);
moveXAnim.From = 0;
moveXAnim.To = 300;
_sb.Children.Add(moveXAnim);
Storyboard.SetTarget(moveXAnim, Person);
Storyboard.SetTargetProperty(moveXAnim, "(Canvas.Left)");
_sb.Begin();
All the examples I find are XAML.
What makes you think it does not work? I assume that Person is a UIElement.
Is your Person element contained inside a Canvas? The example below should work for your code>
<Canvas>
<TextBlock
Text="Hi"
x:Name="Person" />
</Canvas>

Elementhosted WPF-Mediaelement does not allow rotation

I am having a windows forms app.
I want to use a mediaelement in it, so I use the elementhost. I create a wpf usercontrol in which I put a mediaelement. In my app I write the following having the goal in mind to rotate the element.
System.Windows.Controls.MediaElement wm = new
System.Windows.Controls.MediaElement();
wm.LayoutTransform.Value.Rotate(22.0);
elementHost1.Child = wm;
wm.Source = new Uri(dateiname);
wm.Play();
dateiname is the filename.
It plays but it is not rotated. How to rotate wm's video?
Maybe a little later. Try this:
RotateTransform rt = new RotateTransform {Angle = 20.0};
wm.LayoutTransform = rt;

Categories

Resources