WPF Binding StringFormat Short Date String

Try this: <TextBlock Text=”{Binding PropertyPath, StringFormat=d}” /> which is culture sensitive and requires .NET 3.5 SP1 or above. NOTE: This is case sensitive. “d” is the short date format specifier while “D” is the long date format specifier. There’s a full list of string format on the MSDN page on Standard Date and Time Format … Read more

What is the difference between a User Control Library and a Custom Control Library?

In practice custom controls are something you implement on the code level while you can use XAML for user controls. The custom controls extend one of the WPF control base classes and provide additional functionality through code so all the added logic and representation must be implemented inside the code. A user control is technically … Read more

Confused with wpf ComboBox DisplayMemberPath,SelectedValue and SelectedValuePath

I think we can understand this better with an example. See this class: public class Employee { public int Id { get; set; } public string Name { get; set; } } and the following xaml: <ComboBox ItemsSource=”{Binding Source={StaticResource Employees}}” DisplayMemberPath=”Name” SelectedValuePath=”Id”/> DisplayMemberPath points to the Name property, so the value displayed in the ComboBox … Read more

WPF TreeView: How to style selected items with rounded corners like in Explorer

Adding to @Sheridan’s answer This isn’t a 100% accurate but should get you pretty close (it’s using the colors from GridView which is pretty close to Windows Explorer) <TreeView …> <TreeView.Resources> <LinearGradientBrush x:Key=”{x:Static SystemColors.HighlightBrushKey}” EndPoint=”0,1″ StartPoint=”0,0″> <GradientStop Color=”#FFD9F4FF” Offset=”0″/> <GradientStop Color=”#FF9BDDFB” Offset=”1″/> </LinearGradientBrush> <LinearGradientBrush x:Key=”{x:Static SystemColors.ControlBrushKey}” EndPoint=”0,1″ StartPoint=”0,0″> <GradientStop Color=”#FFEEEDED” Offset=”0″/> <GradientStop Color=”#FFDDDDDD” Offset=”1″/> </LinearGradientBrush> … Read more

WPF – Global Style?

Well, sort of – it’s a catch-all approach you can do – put the following element in your App.xaml – all your buttons will change (except the ones you apply a style to, manually). <Style TargetType=”{x:Type Button}”> <Setter Property=”Background” Value=”LightPink”/> <!– You should notice that one… –> </Style> However, if you want to hit only … Read more

WPF textblock binding with List

Convert your List to a single string with “\r\n” as the delimiter in between. and bind that to the TextBlock. Make sure that the TextBlock is not restricted with its height , so that it can grow based on the number of lines. I would implement this as a Value Converter to XAML Binding which … Read more

How to get DataTemplate.DataTrigger to check for greater than or less than?

You could create an IValueConverter, which converts an integer to a boolean based on the CutOff. Then use DataTrigger.Value of True (or False, depending on what you are returning). WPF DataTriggers are strictly equality comparers if I remember correctly. So something similar to: public class CutoffConverter : IValueConverter { public object Convert(object value, Type targetType, … Read more