How to get a ListBox ItemTemplate to stretch horizontally the full width of the ListBox?

I want to have the ListItems to extend with their orange background the full width of the Listbox. Currently they are only as wide as the FirstName + LastName. I’ve set every element I can to: HorizontalAlignment=”Stretch”. I want the background of the ListboxItems to expand as the user stretches the Listbox so I don’t … Read more

How do I get a TextBox to only accept numeric input in WPF?

I’m looking to accept digits and the decimal point, but no sign. I’ve looked at samples using the NumericUpDown control for Windows Forms, and this sample of a NumericUpDown custom control from Microsoft. But so far it seems like NumericUpDown (supported by WPF or not) is not going to provide the functionality that I want. … Read more

Difference between SelectedItem, SelectedValue and SelectedValuePath

What is the difference betweeen the following: SelectedItem SelectedValue SelectedValuePath All these dependency properties are defined in Selector class. I often confuse SelectedItem with SelectedValue , and SelectedValue with SelectedValuePath. I would like to know the difference between them, and also when do we use them, especially SelectedValue and SelectedValuePath. Please explain their use with … 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 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