Transfer routed event from panorama to tile - wpf

I have a app in Metro Style, and in it one page contain the "Panorama" that contain multiple tiles.
In panorama.cs
the event
protected override void OnPreviewMouseDown(MouseButtonEventArgs e)
{}
and
protected override void OnPreviewMouseMove(MouseEventArgs e)
{}
are used to scroll the panorama from left to right and vice versa.
On each "Tile" I have defined a function
private void Tile_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
{}
this is used to open another form.
but due to panorama events, this method is not called and if I comment the above events of "Panorama.cs" I am unable to scroll left to right and vice-versa. How to achieve both.
Thanks in advance

After some RnD and hit and trial testing I found this can be done simply.
Instead of using "MouseDoubleClick" event handler , just use "PreviewMouseDoubleClick".
:)

Related

How to determine if button was clicked or touched?

Is there a way to distinguish whether a button was clicked as in with a mouse or touched using a touchscreen in WPF?
You can subscribe to PreviewMouseDown and PreviewTouchDown.
Page.xaml
<Button PreviewMouseDown="Button_PreviewMouseDown"
PreviewTouchDown="Button_PreviewTouchDown" />
Page.xaml.cs
private void Button_PreviewMouseDown(object sender, MouseButtonEventArgs e)
{
MessageBox.Show("Mouse was used.");
}
private void Button_PreviewTouchDown(object sender, TouchEventArgs e)
{
MessageBox.Show("Touchscreen was used.");
}
I don't believe you'll be able to access the eventargs of either in the actual click event.
If you need to perform work there as opposed to the preview events I would recommend setting an instance variable in the preview events so when you get to the click event you know where you came from.
You have to set up an event handler. In the designer, double click on the button and that will set on up for you.
Then in the code behind add what ever code you want.
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Title = "Clicked";
}
You can add Touch events as well TouchDown, TouchUp, etc.
Windows 7 and its higher versions have the ability to receive input from multiple touch-sensitive devices. WPF applications can also handle touch input as other input, such as the mouse or keyboard, by raising events when a touch occurs.
WPF exposes two types of events when a touch occurs − touch events and manipulation events. Touch events provide raw data about each finger on a touchscreen and its movement. Manipulation events interpret the input as certain actions. Both types of events are discussed in this section.
WPF enables applications to respond to touch. For example, you can interact with an application by using one or more fingers on a touch-sensitive device, such as a touchscreen This walkthrough creates an application that enables the user to move, resize, or rotate a single object by using touch.
Source MSDN : https://msdn.microsoft.com/en-us/library/ee649090.aspx
Also read this codeproject article - http://www.codeproject.com/Articles/692286/WPF-and-multi-touch

Get currentcell in CurrentCellChanged event silverlight

I have added CurrentCellChanged event in my application
this.dgMain.CurrentCellChanged += new EventHandler(dgMain_CurrentCellChanged);
event handler is as below
private void dgMain_CurrentCellChanged(object sender, EventArgs e)
{
}
Now in event handler how I will get current cell clicked.
Thanks in advance :):)
There are lots of ways but without knowing about your data, the only ones that come to mind is:
dgMain.CurrentColumn.GetCellContent
or
dgMain.SelectedItem

Hide cursor wpf WebBrowser control?

neither
<WebBrowser x:Name="wbMain" Cursor="None"></WebBrowser>
nor
*{cursor:none}
is working for me. I can't find any resources online telling me how to accomplish this. The use-case for this is an application that runs full screen meant for viewing only after the setup takes place.
Edit: I forgot to add that the css works as expected when viewing the website in the IE9 browser.
I don't know if this is a good or bad practice but you can add System.Windows.Forms reference
then
private void MouseEnter(object sender, MouseEventArgs e)
{
System.Windows.Forms.Cursor.Hide();
}
private void MouseLeave(object sender, MouseEventArgs e)
{
System.Windows.Forms.Cursor.Show();
}
use this code on mouseEnter form example in web-browser control
For those who dont like to add WinForms reference, try
[DllImport("user32.dll")]
static extern int ShowCursor(bool bShow);
and call ShowCursor(false) when needed.
In app.cs
protected override void OnStartup(StartupEventArgs e)
{
System.Windows.Forms.Cursor.Hide();
}

Hotkeys in Silverlight?

Is there a way to create global keys in Silverlight? I added a KeyDown event handler to the topmost Page element. I can catch the key signal when elements like a Button, TextBox, Calendar, and RichTextBox have focus. But the DatePicker won't let me handle the key down event at the Page level. Any way to make a hotkey in non-OOB SL?
P.S. I am assuming that the DatePicker control behaves differently than others as it is still in the Silverlight Toolkit.
have you tried using the AddHandler method? With this method you can add a handler and define if you want to handle already handled events, too.
In my simple example I added it to the RootVisual in the app.xaml.cs.
private void Application_Startup(object sender, StartupEventArgs e)
{
this.RootVisual = new MainPage();
RootVisual.AddHandler(UIElement.KeyDownEvent, new KeyEventHandler(HandleKeyDown), true);
}
private void HandleKeyDown(object sender, KeyEventArgs e)
{
//Add your keyhandling code here
Debug.WriteLine(e.Key);
}
I tried it with a DatePicker and it works.
Hope this helps!
BR,
TJ
This may help you. The author provides two ways using HTML bridge (when your Silverlight does not have focus) and using the KeyUp event on Application.RootVisual.
I have not tried it myself so I wouldn't know if it's working.

Silverlight UserControl with rectangle as a button

I have a problem using custom made UserControl in Silverlight Page.
The UserControl is generally a rectangle containing a smaller rectangle inside.
I want to use the UControl in a Silverlight MainSite.
i've implemented a method on mouse button down for a smaller rectangle called in here Button1:
public void Button1_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
MessageBox.Show("Hello");
}
How can i use it from a MainSite? From there I can only implement a method like:
private void ImportedControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
firstLeaf.Button1_MouseLeftButtonDown(sender, e);
}
I can not implement a method for Button1.
How can i mek this Work?
HELP:)
I am still not sure I understand the question, but let me take a swing at an answer. Why don't you use a real Button and just template it with a rectangle? This way you get all the benefits of actually having a button while having it look like a rectangle, including the Click event.
Here is a post Scott Guthrie did on control templating with a button.

Resources