DrawingSurface Draw event does not fire - c#

I'm working on a Silverlight application and am trying to use 3D support in my app. I have enabled 3D support with this line:
<param name="enableGPUAcceleration" value="true" />
Also, the application is running on localhost:80 via IIS and this has permission for 3D usage set to Allow.
I have a DrawingSurface in a xaml page and attached its Draw event in which I simply clear the surface to red. The Draw does not fire. So I tried invalidating the DrawingSurface on MouseLeftButtonDown. Here's some code:
private void TestDrawing_Draw(object sender, System.Windows.Controls.DrawEventArgs e)
{
GraphicsDeviceManager.Current.GraphicsDevice.Clear(new Microsoft.Xna.Framework.Color(255, 0, 0));
}
private void TestDrawing_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (GraphicsDeviceManager.Current.RenderMode == RenderMode.Hardware)
{
TestDrawing.Invalidate();
}
}
Checking in debugmode, I find that the MouseLeftButtonDown event does fire. The GraphicsDeviceManager.Current.RenderMode is set to RenderMode.Hardware and the Invalidate() method is executed. But, the Draw event still does not fire.
I've created a testproject which runs via a Developer server on a specific port (50814). Again, enableGPUAcceleration is set to true and permission has been set to Allow. This testproject does fire the Draw event.
So... my large application, running on an IIS server (localhost:80) with enableGPUAcceleration set to true and permission set to Allow does not fire the Draw event. A simple testproject running a Developer server on port 50814 with enableGPUAcceleration set to true and permission to Allow does fire the Draw event.
I've no idea how to enable 3D for my application. Do you guys have any suggestions?!

your code had the draw function working for only once, to make it work continuously, the draw event should be like this:
public void drawingsurface_draw(object sender, DrawEventArgs e)
{
//do some thing here
e.InvalidateSurface();
}

Related

BackRequested event handler event.Handled is ignored

So, as per the docs I attach a handler when I navigate to a page:
protected override void OnNavigatedTo(NavigationEventArgs e) {
/* Attach back listener to handle the back press */
SystemNavigationManager.GetForCurrentView().BackRequested += NavigationPage_BackRequested;
...
}
And I detach it when leaving:
protected override void OnNavigatingFrom(NavigatingCancelEventArgs e) {
SystemNavigationManager.GetForCurrentView().BackRequested -= NavigationPage_BackRequested;
e.Cancel = false;
}
And I mark the event as handled to prevent the system from handling it:
private void NavigationPage_BackRequested(object sender, BackRequestedEventArgs e) {
e.Handled = true;
}
But the system still handles the back click and I get navigated away. Why?
Your code shown above is working fine (tested on my machine), but the big question is: do you try to cancel a system provided navigation event or a Frame.GoBack() event implemented by the software button of your application?
SystemNavigationManager: Provides a way for an app to respond to system provided back-navigation events.
If you look at the backwards navigation documentation, only certain back buttons (hardware/software) are system provided events, e.g. the software button at the bottom in Tablet mode.
However quite a few project templates (in Visual Studio or from MVVM libraries) also provide a software back button (quite often at the top left) and wire this event to the Frame.GoBack() method. This is NOT a system provided event and can't be cancelled this way. Reasoning: You (or the framework used) is calling the GoBack() explicitly, so why would it have to be cancelled in this scenario.

Stop action when button is released

In my WP8 app that controls Lego Mindstorms I have a Button with UIElement.Hold Event that triggers method runMotor() When I release the Button motor keeps on going but I would like it to stop. Method for stopping is stopMotor(), I've already tried to assign it to KeyUp Event but it doesn't work. Any solutions?
You can try to call stopMotor() in ManupulationCompleted event. Note that ManipulationCompleted event will get invoked after any gesture manipulation including Tap, Double Tap, Hold, and other gesture. Take that into account. If application scenario is still simple, checking if motor already running before calling stopMotor in ManipulationCompleted event handler maybe enough :
private void MyButton_ManipulationCompleted(object sender, ManipulationCompletedEventArgs e)
{
if(isMotorRunning) stopMotor();
}

How to control WPF Controls using Kinect hand pointer?

I have been developing a desktop application in C# that uses Kinect to detect gestures.I want to obtain the user information from Google+ using google+ APIs.
The problem is,as I use Kinect hand pointer I can click only elements like kinect tile buttons provided by Kinect region.
I use embedded browser control for authenticating Google+.But for accessing Google+ using OAuth 2.0, I need the consent from the user .provided the user clicks the Allow access button which can't be done by Kinect hand pointer.
Is there any way to manipulate the mouse click programmatically or to access the browser using the Kinect hand pointer?
You can't mouseclick programically, but You can trigger the onclick event handler manually, like:
Button_Click(object sender, EventArgs e) {} // - the function that handles the onclick
You trigger it manually like this:
YourKinectFunction()
{
Button_Click(this, new EventArgs());
}
It will work just as if you clicked the button with mouse.
The Button_Click(object sender, EventArgs e) is the function which is executed when the event happens. If you trigger the event in your code, the handler will fire. The function doesn't 'know' who triggered the event (unless you specify it in sender parameter).

Intercept every mouse click to WPF application

I'm looking to intercept every mouse click in my WPF application. Seems this should be easy with the command routing mechanism, but sorry I'm not finding anything.
My application implements several security levels, and has the requirement to automatically revert to the most restrictive level if no one interacts with (clicks) the application in x minutes. My plan is to add a timer that expires after x minutes and adjusts the security level. Each mouse click into the application will reset the timer.
You can register a class handler:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
EventManager.RegisterClassHandler(typeof(Window), Window.PreviewMouseDownEvent, new MouseButtonEventHandler(OnPreviewMouseDown));
base.OnStartup(e);
}
static void OnPreviewMouseDown(object sender, MouseButtonEventArgs e)
{
Trace.WriteLine("Clicked!!");
}
}
This will handle any PreviewMouseDown event on any Window created in the application.
<Window .... PreviewMouseDown="Window_PreviewMouseDown_1">
</Window>
This should work for you.
This fires even if other MouseDown events fire for components that it contains.
As per Clemens suggestion in the comments, PreviewMouseDown is a better choice than MouseDown, as that makes sure you can't stop the event bubbling from happening in a different event.
You have a few options:
Low level mouse hook:
http://filipandersson.multiply.com/journal/item/7?&show_interstitial=1&u=%2Fjournal%2Fitem
WPF Solution (I'd check to see if this does what you need first):
WPF. Catch last window click anywhere

How can I listen for left mouseclicks on a canvas in a C# WPF?

I am trying to listen for a mouse click anywhere on my window (Except for the locations where the buttons are, but I'll deal with that later) and then return the point (x,y) of the location.
here is the relevant code:
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
Console.WriteLine("mouseLeft is clicked");
Point x = e.MouseDevice.GetPosition(this);
Console.WriteLine(x.X);
Console.WriteLine(x.Y);
}
<Canvas MouseLeftButtonDown="Grid_MouseLeftButtonDown">
When I click, nothing is printed. What am I doing wrong exactly? The first method is inside mainWindow.Xaml.cs.
thanks in advance.
Set background to transparent and set size of canvas!
Sometimes things won't be written to the console correctly in GUI Apps, try using Debug.WriteLine, MessageBox.Show, or settings a breakpoint to see if the event is being fired.
The code you have there looks perfectly fine.

Categories

Resources