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();
}
Related
Let's say I got the following ComboBox in my XAML:
<ComboBox x:Name="cmbOinkOink" Loaded="cmbOinkOink_Loaded" />
And I have my cmbOinkOink_Loaded method deep in here:
namespace PiggyWPF.Classes.EventHandler
{
class ComboBoxEventHandler
{
public void cmbOinkOink_Loaded(object sender, RoutedEventArgs e)
{
// Do Stuff...
}
}
}
How am I going to tell XAML that the cmbOinkOink_Loaded is going to be found under PiggyWPF.Classes.EventHandler.ComboBoxEventHandler?
I am not sure there is a straight forward way to achieve this behavior from xaml.
but you can do this easily from code behind.
class Control
{
...
public void cmbOinkOink_Loaded(object sender, RoutedEventArgs e)
{
_handlerObject.DoStuff();
}
You will have to forward the method call one way or another, either via the code behind of that XAML that defines the ComboBox or by using e.g. the ExecuteCommandAction from Interactivity, which requires you to provide a command in you original class instead of just a method, ideally static or otherwise easily accessible so you can use x:Static or something similar in the action's XAML.
(Posted on behalf of the OP).
I guess my only way was to add the following code to my main class:
private void cmbOinkOink_Loaded(object sender, RoutedEventArgs e)
{
using (ComboBoxEventHandler cmbEvent = new ComboBoxEventHandler())
{
cmbEvent.cmbOinkOink_Loaded(ref sender, e);
}
}
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".
:)
I'm newbie in Silverlight and I need to activate MouseRightButtonDown(object sender, MouseButtonEventArgs e) from an another event handler in my application.
I have found, that in WPF it is possible to do somthing like this:
public void OnContextMenuOpened(object sender, RoutedEventArgs e) {
MouseButtonEventArgs args = new MouseButtonEventArgs(
InputManager.Current.PrimaryMouseDevice,
0,
MouseButton.Right);
MouseRightButtonDown(sender, args);
}
But I have in Silverlight neither InputManager-Class nor MouseButton-Class... It is generally possible to realise something like that?
I want to do it, because I try to select an DataGridRow(within an custom control) with help of right-mouse-button. Without context menu it is easily possible, but when I switch context menu on, then context menu opens and event will not fired...
My code snippet:
public override void OnApplyTemplate() {
DataGrid = (DataGrid)GetTemplateChild("DataGrid");
DataGrid.MouseRightButtonDown += DataGridMouseRightButtonDown;
ContextMenu = (ContextMenu)GetTemplateChild("ContextMenu");
ContextMenu.Opened += OnContextMenuOpened;
}
private void DataGridMouseRightButtonDown(object sender, MouseButtonEventArgs e) {
//My code to select an DataGridRow
}
public void OnContextMenuOpened(object sender, RoutedEventArgs e) {
//This event-handler now will be always activated if I do
//right-mouse-button-click
}
Thanks a lot for help!
The Results of my research has shown, that it is impossible in silverlight -.-
How can I get a current focused control in WPF?
I found some solution for WinForms, but invoking WIN32 API function, didn't work in WPF?
Is there any way for doing it in WPF?
I know this is a late answer, but maybe people searching can find this helpful, I it found on msdn in the "Navigating Focus Programmatically" section close to the bottom of the page:
UIElement elementWithFocus = Keyboard.FocusedElement as UIElement;
Here's what I did
protected override void OnPreviewLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
lostFocusControl = e.OldFocus;
}
private void PauseButton_PreviewKeyDown(object sender, KeyEventArgs e)
{
// invoke OnPreviewLostKeyboardFocus handler
}
Is it possible to bind the multiple commands to the button.
I have a user control, which i am calling in my main application (parent application).
I want to handle a click command on both the controls (the user control as well as on the main window). However i am only able to get one.
Is there any way in which i can get this.
Any help is really appreciated.
Code Snippet:
public class MainWindowFooterCommands
{
public static readonly RoutedUICommand FooterClickLocalCommand = new RoutedUICommand("Local Button Command", "FooterClickLocalCommand", typeof(MainWindowFooterCommands));
}
private void MainWindowFooterBindCommands()
{
CommandBinding cmdBindingBXClick = new CommandBinding(MainWindowFooterCommands.FooterClickLocalCommand);
cmdBindingBXClick.Executed += ClickCommandHandler;
CommandBindings.Add(cmdBindingBXClick);
}
void ClickCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
//Do Something
}
//Parent Control holding an instance of the footer control.
class MainWindow {
public MainWindow()
{
CommandBinding cmdBindingBXClick1 = new CommandBinding(MainWindowFooterCommands.BXClickMainWindowCommand);
cmdBindingBXClick1.Executed += LoadParent;
CommandBindings.Add(cmdBindingBXClick1);
}
public void LoadParent(object sender, ExecutedRoutedEventArgs e)
{
LoadParentWindow();
}
}
Regards,
Tushar
You might be trying to aggregate multiple commands, which is a natural thing to want to do.
If you are using Prism, there is a class builtin for this called the CompositeCommand (scroll down a bit): https://msdn.microsoft.com/en-us/library/ff921126.aspx
Otherwise, Josh Smith has a very good article on his implementation called a "Command Group": http://www.codeproject.com/KB/WPF/commandgroup.aspx
There are some very nice scenarios you can rollup like this (for instance, "Save All"). A good tool for your bag of tricks.
AFAIK WPF doesnt offer anything out of the box to support multiple commandbindings at various levels, but you could try the following:
void ClickCommandHandler(object sender, ExecutedRoutedEventArgs e)
{
IInputElement parent = (IInputElement) LogicalTreeHelper.GetParent((DependencyObject)sender);
MainWindowFooterCommands.BXClickMainWindowCommand.Execute(e.Parameter, parent);
}
You might have to test whether your parent really is an IInputElement, though.