Change debug design forms within aproject VS2010 - winforms

This probably has a one click solution, i know debugging web pages in VS2010 just needs to set as start page to debug the given window, but i can't seem to change it in windows forms. Keeps debugging the old one, any clues to how to set debugging form?? thanks.

Open the Program.cs file and you can set the Startup Form there:
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
To change this, Right Click the Project > Properties and set the startup object there.

Related

WPF .NET project does not have a .csproj file

I have created a WPF project in Visual Studio 2017 and it runs without any issues.
However, I noticed that many of the guides online are using a .csproj to perform several tasks. When I tried searching for my .csproj file, I couldn't find one.
Is there something wrong with my project?
This is what it looks like:
The closest thing I have is my App.config files
You can right click the solution then click Unload Project. From there right click again and you will see 'Edit csproj'. That is an easy way to edit it in VS.
The Main() method is created automatically. If you want to provide your own you have to (tested in VS2013 and VS2017):
Right-click App.xaml in the solution explorer, select Properties
Change 'Build Action' to 'Page' (initial value is 'ApplicationDefinition')
Then just add a Main() method to App.xaml.cs. It could be like this:
[STAThread]
public static void Main()
{
var application = new App();
application.InitializeComponent();
application.Run();
}

WPF - Display usercontrol dll's name as they load in splash screen

I am in the process of writing a WPF application that hosts 10+ usercontrols I have written. What I would like to do is modify the code from "Wonko the Sane"'s answer in this post
Is there a way to show a splash screen for WPF application?
to dynamically show the name of these usercontrol dll's as they load.
I have not been able to find anywhere how to get the names of dll's as they load.
Any assistance would be appreciated.
Thanks, Jim
Sorry, but you won't be able to do that. The WPF Framework loads before your program starts executing. The best that you'll be able to do is to add the names of the relevant DLLs into a string collection and then loop through them, displaying each one temporarily. Even if you could display what was being loaded, the chances are that they'd actually load so quick that you wouldn't see anything anyway.
It's also worth pointing out that it is only really worth having a splash screen in a WPF Application if you have a real lot of initialisation loading to do. In that case, you can show what the application is doing, but you'll probably find that in most cases, the loading is still done too fast for the UI to update in time.
You can get the current application domain and then use AssemblyLoad event to get loaded Dll name.
AppDomain MyDomain = AppDomain.CurrentDomain;
MyDomain.AssemblyLoad += new AssemblyLoadEventHandler(SplashControllerObject.LocalEventHandler);
private void LocalEventHandler(object sender, AssemblyLoadEventArgs args)
{
//use sender.LoadedAssembly.FullName for DLL name loaded
}

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));
}

System tray application to notify every 2 hours

I am trying to make a system tray application that loads on startup and pops a balloon text every 2 hours. If there is such an example its great.
I am looking to use.
WPF,
Timers,
Delegates, events
I am not sure if these are enough or do I need something more.
Thanks in advance.
I think you will be fine with those. All you need is actually a NotifyIcon and a Timer. I've accomplished similar this way, except I wasn't using WPF (I rather used the 'classical' Window designer).
The simplest way to let your app start on startup would probably be to put it into Startup folder in the Start menu, there's actually no need to use the registry.
First of all here is what you need about starting your application on system startup :
Lets say I have a checkBox and I want to start my application on windows startup if this checkBox is activated :
RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
private void checkBox_autoStart_Checked(object sender, RoutedEventArgs e)
{
rkApp.SetValue("Your Application Name Here",Assembly.GetExecutingAssembly().Location);
}
and about the deactivation of that you do the follwoing :
private void checkBox_autoStart_Unchecked(object sender, RoutedEventArgs e)
{
rkApp.DeleteValue("Your Application Name Here", false);
}
p.s : Your application name will appear on the task manager the way you write it up there
And about using a notify Icon , well actually WPF doesn't support a ready made one so either you use the Windows Forms Notify Icon or you use the one mentioned in a nother answer from codeproject.com
if you wanted to use the one that already exists in windows forms , you have to add a reference to System.Windows.Forms in your project
A windows service may be the best thing for running in the background, but it may be tricky to get access to the GUI from a service (I don't think it's trivial).
For a WPF desktop app to do a tray notification, see this project with demo and source code: http://www.codeproject.com/KB/WPF/WPF_xaml_taskbar_window.aspx
To get the notification every 2 hours, you can use a DispatcherTimer:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/aaffea95-e735-492d-bd8a-2fdf7099a936

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