The name ‘InitializeComponent’ does not exist in the current context

If I create a new project in Visual Studio 2010 SP1 and select “WPF Application” and tries to build the generated application, I get the error The name ‘InitializeComponent’ does not exist in the current context. I got a similar error this morning when I tried to build my current project. Yesterday, I had no … Read more

How to bind RadioButtons to an enum?

I’ve got an enum like this: public enum MyLovelyEnum { FirstSelection, TheOtherSelection, YetAnotherOne }; I got a property in my DataContext: public MyLovelyEnum VeryLovelyEnum { get; set; } And I got three RadioButtons in my WPF client. <RadioButton Margin=”3″>First Selection</RadioButton> <RadioButton Margin=”3″>The Other Selection</RadioButton> <RadioButton Margin=”3″>Yet Another one</RadioButton> Now how do I bind the RadioButtons … Read more

What’s the difference between StaticResource and DynamicResource in WPF?

When using resources such as brushes, templates and styles in WPF, they can be specified either as StaticResources <Rectangle Fill=”{StaticResource MyBrush}” /> or as a DynamicResource <ItemsControl ItemTemplate=”{DynamicResource MyItemTemplate}” /> Most of the times (always?), only one works and the other will throw exception during runtime. But I’d like to know why: What is the … Read more

How do I exit a WPF application programmatically?

How is one supposed to exit an application such as when the user clicks on the Exit menu item from the File menu? I have tried: this.Dispose(); this.Exit(); Application.ShutDown(); Application.Exit(); Application.Dispose(); Among many others. Nothing works. 18 s 18 To exit your application you can call System.Windows.Application.Current.Shutdown(); As described in the documentation to the Application.Shutdown … Read more

How do I use WPF bindings with RelativeSource?

How do I use RelativeSource with WPF bindings and what are the different use-cases? 14 s 14 If you want to bind to another property on the object: {Binding Path=PathToProperty, RelativeSource={RelativeSource Self}} If you want to get a property on an ancestor: {Binding Path=PathToProperty, RelativeSource={RelativeSource AncestorType={x:Type typeOfAncestor}}} If you want to get a property on … Read more

In WPF, what are the differences between the x:Name and Name attributes?

Sometimes it seems that the Name and x:Name attributes are interchangeable. So, what are the definitive differences between them, and when is it preferable to use one over the other? Are there any performance or memory implications to using them the wrong way? 15 s 15 There really is only one name in XAML, the … Read more

Metadata file ‘.dll’ could not be found

I am working on a WPF, C# 3.0 project, and I get this error: Error 1 Metadata file ‘WORK=- \Tools\VersionManagementSystem\BusinessLogicLayer\bin\Debug \BusinessLogicLayer.dll’ could not be found C:\-=WORK=- \Tools \VersionManagementSystem\VersionManagementSystem\CSC VersionManagementSystem This is how I reference my usercontrols: xmlns:vms=”clr-namespace:VersionManagementSystem” <vms:SignOffProjectListing Margin=”5″/> It happens after every failed build. The only way I can get the solution to compile … Read more