Can't exit WPF Application - wpf

I know this question has already been answered but despite my efforts I can't close my app programatically. I've tried this, which doesn't work :
private void CloseAppCommand_Executed(object sender, ExecutedRoutedEventArgs e)
{
System.Windows.Forms.Application.Exit();
}
and this (but Visual Studio 2010 doesn't recognize it) :
Application.Current.Shutdown();
Does someone know why these solutions don't work ? I thought it maybe was because of WPF vs WinFOrms, but I'm not sure.

Application.Current.Shutdown(); is the way you exit a WPF application. You've probably messed up your project references. See here for the references you need for a WPF application.

Found it !
I didn't use the right class :
System.Windows.Application.Current.Shutdown();

Related

WPF - Telerik issue? Working fine in Windows 7 environment but not Windows 8.1

Hi, guys. I know the information is sort of brief but can any good souls here, able to point out to me what does this error message means exactly?
The codes are running just fine at Windows 7 platform. However, it crashes when I use Windows 8.1 to run it.
I am almost sure that the problem has something to do with telerik. This is because when I remove the related RadGridView from my xaml, it works fine. That RadGridView is binding an ICollection as its ItemSource.
Quite desperate at the moment. Thank you in advance for any help guys! Appreciate it :)
The problem is caused by touch screen / accessibility support in Windows 8.x
You might be able to solve this by disabling UI automation in Telerik like this:
using Telerik.Windows.Automation.Peers;
public partial class App : Application
{
public App()
{
AutomationManager.AutomationMode = AutomationMode.Disabled;
this.InitializeComponent();
}
}

WPF mess, crash visual studio 2010 hard crash when any xaml opened with WPF designer

So I am the new Architect for a very large WPF application. My main goal is performance, but my personal goal is the ability to view xaml in the WPF designer without a hard VS crash. We are currently editing xaml in xml editor, which is inefficient to say the least. I am totally clueless on what I can do to find the source/s of problem as VS does say much about why it's crashing. If anyone can kick my ass into the right direction, it would be greatly appreciated.
Some facts to possibly help with solution.
We are using VS 2010 Premium
There are around 70 merged dictionary files.
We are using Telerik controls.
We are on .net 4
It is a primarily VB.Net application
Let me know if I can provide any other useful information.
you can use the UserControl loaded event sometimes
private void connectionControl_Loaded(object sender, RoutedEventArgs e)
{
if (System.ComponentModel.DesignerProperties.GetIsInDesignMode(this) == false)
{
//act normally
}
}

How can I debug Windows Runtime data bindings?

What techniques are there for debugging issues with data binding in a Windows Metro style application? Are there techniques available like those for WPF and Silverlight applications, described at:
How can I debug WPF bindings?
Debugging Data Bindings in a WPF or Silverlight Application
How can I turn binding errors into runtime exceptions?
EDIT: I was originally asking about WinRT data binding debugging techniques so that I could troubleshoot the issue described at Metro: Why is binding from XAML to a property defined in code-behind not working?. I eventually found a solution to this issue, but experimenting with the working solution, I did not see any message in the Visual Studio 11 output window when I purposely misspelled the property name so that it would not be found. It also does not appear that PresentationTraceSources is available to WinRT apps.
Another possible solution:
sealed partial class App : Application
{
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
DebugSettings.BindingFailed += OnDebugSettingsOnBindingFailed;
}
private void OnDebugSettingsOnBindingFailed(object sender, BindingFailedEventArgs args)
{
new MessageDialog(args.Message).ShowAsync();
}
...
}
Original source: http://www.tozon.info/blog/post/2012/07/23/Debugging-WinRTXAML-bindings.aspx
If you look at the output window in VS you will see data binding trace messages on errors. You get this automatically for C++ applications and for managed applications you have to turn on unmanaged debugging to see them. This is an area we are looking to improve on, but for now you have the ability to turn them on and see the trace outputs.
In VS11 beta, the templated projects offer a way to help debug binding errors.
I wrote it up here http://www.kelvinhammered.com/?p=150
I always use immediate window to track binding issues.
Here's what msdn says about it :
In some settings configurations, first-chance exception notifications
are displayed in the Immediate window.
To toggle first-chance exception notifications in the Immediate window
On the View menu, click Other Windows, and click Output.
Right-click on the text area of the Output window, and select or
deselect Exception Messages.
(in fact default setting was ok for me in vs2010)
hope this can help.

Prism App Does Not Exit When Closed

I am learning prism and I have hit a problem.
I have made an app very similar to the one that Mike Taulty makes in is great tutoral about Prism. The biggest difference is that my app is a WPF app instead of Silverlight.
I am finding that I have hit a problem though. When I close the main shell window, the app does not exit. The window goes a way, but the debugger is still active.
I have tried looking for call stacks and such, but Visual Studio just tells me that it is "External Code".
Any ideas on what I can do/look for to fix this?
Override the OnStartup method in the code behind of your App.xaml, and add this:
this.ShutdownMode = ShutdownMode.OnMainWindowClose;
HTH
The answer of Dyer solve only part of the problem.
I had the same issue, and after a while I found out that region navigation commands are not working well either.
The problem was with the Shell creating in Bootstrapper.
When I fixed that, I got 2 Shell windows instances.
Why?
The real problem was the startup Uri in the app.xaml.
You can't have both startup Uri with Shell creation in Bootstrapper.
Remove it from the app.xaml, fix your Shell and no need is this "Patch" and your app will behave as it should, it will close when you close the Shell.
Again, this is only a symptom, other issues will rise if you don't fix the Shell creation.
protected override DependencyObject CreateShell()
{
return this.Container.Resolve<Shell>();
}
protected override void InitializeShell()
{
base.InitializeShell();
Application.Current.MainWindow = (Shell)this.Shell;
Application.Current.MainWindow.Show();
IRegionManager regionManager = this.Container.Resolve<IRegionManager>();
regionManager.RegisterViewWithRegion(RegionNames.MainRegion, typeof(MainView));
}

LicenseException for Xceed DataGrid for WPF

I have developed a simple DB-editing app using Xceed's excellent DataGrid for WPF (UX Edition version 3.7), which is now ready for deployment... except that when I run it on a machine other than the development one where it was built, I am getting the runtime exception for invalid licensing.
I have included my license key in the App.xaml.cs exactly as specified in the Xceed docs, like so:
public partial class App : System.Windows.Application
{
protected override void OnStartup(StartupEventArgs e)
{
Xceed.Wpf.DataGrid.Licenser.LicenseKey = "DGF37-xxxxx-xxxxx-xxxx";
base.OnStartup(e);
}
}
The correct version of the DataGrid DLLs are being included in the setup and the application's program directory, and there are no other versions on the target machine.
Debugging doesn't show me anything useful other than the LicenseException that is thrown when the code tries to use the DataGrid, with the message that reads "Xceed.Wpf.DataGrid.Licenser.LicenseKey property must be set to a valid license key in the code of your application before using this product..."
Any idea what's going wrong here?
Oh, poop... figured it out, and it was a stupid mistake. My OnStartup event was misplaced, outside of the app's namespace.

Resources