Windows Phone 8.1 ManipulationDelta Event - c#

I'm really confused about this Topic. None of the tutorials I found to e.g. move objects around when there's touch input works. For example they all do something like this:
Control.AddHandler(UIElement.ManipulationStartedEvent, new EventHandler
<ManipulationStartedEventArgs>(Control_ManipulationStarted), true);
But there's no ManipulationStartedEventArgs, VS2013 can't find it and there's no way to add a using directive. Are those tutorials old and did MS change the way the ManipulationDelta works?
Adding it with the EventHandler section of the Properties section again doesn't work, no Event is fired no matter what I'm trying to do.

For manipulation to work the UI Element must have ManipulationMode property set to something other than None or System to be a manipulation event source; i.e Set ManipulationMode to TranslateX if you want an event to fire on a horizontal pointer movement.
For UI manipulation in Windows Universal you have 3 events:
ManipulationStarted
ManipulationDelta
ManipulationCompleted
Each with their own EventArgs under System.Windows.Input namespace
ManipulationStartedEventArgs
ManipulationDeltaEventArgs
ManipulationCompletedEventArgs
The problem may however be the type of UI Element that you are using, not all accept/generate manipulation events.
Examples of UI Elements that don't:
WebView
(I expect Canvas but not sure, haven't tested)
Examples of UI Elements that do:
Textblock
ListView

Related

PointerCaptureLost c# UWP Windows 10

I am working on UWP Windows 10 application using C#.
For some animation I was relying on PointerPressed and PointerReleased events. Hoping that these will be fired in pairs. And I was wrong. Check what Microsoft has to say about this:
https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.uielement.pointercapturelost
Now, I am using PointerCaptureLost in place of PointerReleased and it is working fine. Only problem is if I use AddHandler for PointerCaptureLost it shows an error: "UIElement.PointerCaptureLost can only appear on the left hand side of += or -=". It is only working when added as +=.
Any thoughts why it is like this?
You should use UIElement.PointerCaptureLostEvent with AddHandler, because that is the Routed Event ID, which specifies the event. In contrast, x.PointerCaptureLost (where x is the name of the control) is the field that represents the Event Handler itself.
I had no problem using both x.AddHandler(UIElement.PointerCaptureLostEvent, ...) and x.PointerCaptureLost += ... in my code. Moreover, as this link suggests, they both translate to the same
call to AddRoutedEventHandler.

How I will get dropping media on mediaelement in wpf?

I am working with mediaelement in wpf, but the problem is I can't drop media on medaiaelement.
can anyone tell me the solution.the following code is .cs file code. I set allow drop property= true
private void mediaElement1_Drop(object sender, System.Windows.DragEventArgs e)
{
String[] FileName = (String[])e.Data.GetData(System.Windows.Forms.DataFormats.FileDrop, true);
if (FileName.Length > 0)
{
String VideoPath = FileName[0].ToString();
mediaElement1.Source = new Uri(VideoPath);
mediaElement1.Play();
}
e.Handled = true;
}
Tried it myself. Actually it will work after you play something there.
Here's the point: assume we have a Grid:
<Grid AllowDrop="True"></Grid>
It won't allow drop.
Now the following
<Grid Background="Transparent" AllowDrop="True"></Grid>
Will allow drop.
The first Grid doesn't have background at all, so actually there's no way to drop anything on it - there's no grid. And in second case there is grid's background even though we can't see it.
The same thing applies to MediaElement. Unfortunately it doesn't have any Background or Content property, so it won't allow drop until you start playing something there.
Solution is to handle drop on MediaElement parent container.
By the way, don't forget to set LoadedBehavior="Manual" for MediaElement so that it will play dropped file.
EDIT.
Here is explanation why MediaElement doesn't allow drop till any content was loaded in it.
Every WPF component is in fact composed of some other basic elements: Borders, Grids, ContentPresenters etc. So something inside the MediaElement handles drop. I cannot tell you what element it is because MediaElement's Template is not accessible. But it really doesn't matter what exactly is the element that handles drag and drop there. What does matter is that there's is nothing material in MediaElement's area until you load content on it - just like in case of my example with Grid at the beginning of this post. I mean that when you move mouse cursor over it's area there is nothing between cursor and MediaElement's container. Try to handle MouseDown event: result will be the same - it won't fire until you load any video. Why? Because there is nothing to raise event. Nothing cannot raise anything.
As I mentioned before there is great difference between Background="{x:Null}" and Background="Transparent": in first case there's no background brush, no background, but in second case there is one. Feel the difference.

AutoCompleteComboBox Arrow Up/Arrow Down keys to scroll list

I created a simple AutoCompleteBox in my WPF app and it loads great with code intercepting the Populate event, but when the list pops up and I hit the arrow down key and get to the end of the list the vertical scroll bar doesn't scroll.
The values keep changing in the field like it is scrolling through them, but the scroll bar doesn't move.
If I use the mouse it scrolls fine.
I just need the arrow key to scroll it.
Any ideas/suggestions?
I am new to WPF and have searched forever for this fix.
Attach a SelectionChanged event and then, inside the handler:
private void AutoCompleteBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
AutoCompleteBox box = (AutoCompleteBox)sender;
ListBox innerListBox = (ListBox) box.Template.FindName("Selector", box);
innerListBox.ScrollIntoView(innerListBox.SelectedItem);
}
I see the same behavior. I found a post on codeplex talking about a different issue but at the bottom of the post they have a class AutoCompleteBoxEx that supports ScrollIntoView, so you can hook up the SelectionChanged even and this should get you the behavior you want. I have no idea why this is not baked in. I have had a chance to test out the posted code.
Update
Just pasted the code from the post into a class and used it in the XAML by changing AutoCompleteBox to AutoCompleteBoxEx and adding namespace for AutoCompleteBoxEx and it worked fine. You don't have to specify any event in the XAML, nor do you need to add any code to the code behind.

Is there something like an "OnPaint" method in Silverlight?

Is there something like an "OnPaint" method in Silverlight?
Back when I was writing C++, I found that it was easy to use the OnPaint event to customize the display of a class to the screen?
Is there an equivalent in Silverlight? If I want to do something when a UserControl is displayed on the screen, what method would I override?
I noticed this post:
C# WPF OnPaint method alternative?
but it seems that in Silverlight, thre is no "OnRender" method for a UserControl class.
OnPaint was a workaround... to allow you to customise the appearance of controls. That was because you did not have much control over the default appearance of any controls in WinForms applications.
With Silverlight that all changes. Every control is now effectively skinned, using templates and styles, and there are few limitations on how you can customise them. There are far too many links so I just grabbed a couple for you.
Get yourself a good book on Silverlight and learn the proper way to work with it (not around it). This one is one of my favorites.
If you have specific things you are trying to do, to the appearance of user controls, best to list those instead and find out the best way to do it the Silverlight way. :)
You haven't specified what you're trying to do. If you just want to know when a frame is being rendered, the CompositionTarget.Rendering Event will tell you that. If you actually want to draw on the frame being rendered, you cannot do so.
It is LayoutUpdated.
As in:
...
this.LayoutUpdated += new EventHandler(LayoutUpdated);
}
void LayoutUpdated(object sender, EventArgs e)
{}

Silverlight toolkit - intercepting drag start

I can't find a way to intercept the beginning of the drag operation in SLToolkit; I need that in order for my custom controls to indicate the regions where the item could be dropped. Unfortunately, there is no IsDragInProgressChanged event; I looked at the sources and the only way I found was to subclass all DragDropTarget<,>s and override OnItemDragStarting method, which, in my opinion, is way too complicated and intrusive. Anyone knows of a better method?
Both the PanelDragDropTarget and ListBoxDragDropTarget have an event named ItemDragStarting. Adding an event handler in the XAML and handling it in the code-behind should be all you need.

Categories