Touch command in a (whole) grid
Hi guys, any idea how to bind a command from a grid in xaml like a button?
(obviusly I don't want to put the grid within a button)
thanks!
(obviusly I don't want to put the grid within a button)
thanks!
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Touch command in a (wole) grid
Hi,
I'm sorry but I don't understand what you are trying to accomplish
Could you please elaborate a bit more the situation you want to solve?
Thanks.
I'm sorry but I don't understand what you are trying to accomplish

Could you please elaborate a bit more the situation you want to solve?
Thanks.
Re: Touch command in a (wole) grid
Hi, basically something like <Grid Command="MyCommand" ....">
I don't know if possible but also it would be great something like the next as well:
<Grid TouchDown="MyTouchDownCommand" ....">
<Grid TouchMove="MyTouchMoveCommand" ....">
<Grid DoubleTouch="MyDoubleTouchCommand" ....">
an so on with different touch events and controls (images, textblocls, etc..)
cheers!
I don't know if possible but also it would be great something like the next as well:
<Grid TouchDown="MyTouchDownCommand" ....">
<Grid TouchMove="MyTouchMoveCommand" ....">
<Grid DoubleTouch="MyDoubleTouchCommand" ....">
an so on with different touch events and controls (images, textblocls, etc..)
cheers!
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Touch command in a (wole) grid
You can use attached properties to add this kind of behaviors.
And then you can set this property in your xaml:
Code: Select all
public class TouchBehaviors: DependencyObject
{
public static DependencyProperty TouchDownProperty = DependencyProperty.Register(
"TouchDown", typeof(ICommand), typeof(TouchBehaviors),
new PropertyMetadata(null, new PropertyChangedCallback(OnTouchDownChanged)));
public static ICommand GetTouchDown(DependencyObject d)
{
return (ICommand)d.GetValue(TouchDownProperty);
}
public static void SetTouchDown(DependencyObject d, ICommand command)
{
d.SetValue(TouchDownProperty, command);
}
private static void OnTouchDownChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
UIElement element = d as UIElement;
if (element != null)
{
element.TouchDown += OnTouchDown;
}
}
private static void OnTouchDown(object sender, TouchEventArgs e)
{
DependencyObject d = sender as DependencyObject;
if (d != null)
{
ICommand command = GetTouchDown(d);
if (command != null)
{
if (command.CanExecute(null))
{
command.Execute(null);
}
}
}
}
}
Code: Select all
<Grid local:TouchBehaviors.TouchDown="{Binding TouchDownCommand}"/>
Re: Touch command in a (wole) grid
Awesome thank you so much!
My suggestion would be to add a chapter with this subject to the documentation, as it could probably help others.
cheers!
My suggestion would be to add a chapter with this subject to the documentation, as it could probably help others.
cheers!
Who is online
Users browsing this forum: Google [Bot] and 1 guest