When should I use dependency properties in WPF?

Dependency Property is a broad concept to explain which might take couple of pages to write. So just to answer your main question, Dependency property is used where You know the property is going to be the binding target i.e you are creating a user control/custom control and want property that should be binding driven. … Read more

Add WPF control at runtime

After you add the your control to the Canvas you need to specify the top and left co-ordinates using the Canvas.Top and Canvas.Left attached properties as follows. var light = new LightUserControl(2); HouseCanvas.Children.Add(light); Canvas.SetLeft(light, 20); Canvas.SetTop(light, 20);

Why is my WPF textbox “kinda” readonly?

I was encountering a problem very similar to this. After doing a little research, I found a similar problem listed in MSDN: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c68d5f3c-c8cc-427d-82e3-6135d075a304/ According to the answer to the post, the problem has to do with WPF and WinForms having two very different ways of handling text input. Fortunately, the post listed above gives the … Read more

What is the WPF XAML Data Binding equivalent of String.Format?

You can use MultiBinding + StringFormat (requires WPF 3.5 SP1): <TextBox.Text> <MultiBinding StringFormat=”{}{1:#0}% up, {2:#0}% down”> <Binding Path=”PercentageOne” /> <Binding Path=”PercentageTwo”/> </MultiBinding> </TextBox.Text> Regarding Run.Text – you can’t bind to it but there are some workarounds: http://fortes.com/2007/03/20/bindablerun/ http://paulstovell.net/blog/index.php/attached-bindablerun/

Restart application using C#

I don’t think there’s a direct method in WPF like there is in WinForms. However, you could use methods from the Windowns.Form namespace like this: (You might need to add a reference to the System.Windows.Form assembly) System.Windows.Forms.Application.Restart(); System.Windows.Application.Current.Shutdown();