C# – How to dinamically select a DataTemplate for each item in a list

Using a DataTemplateSelector, we can determine at runtime which DataTemplate to apply to show items in a ItemsControl derivated control like the GridView, ListView, ListBox, etc. For example, suppose we have a list of items of the below type: And we want to show either text or image content in the same list, based on … Continue reading “C# – How to dinamically select a DataTemplate for each item in a list”

C# – How to make items of ListView fill the entire list width

One thing that happened to me often was the items of an ItemsControl derivative (like a ListBox or ListView) not fill the full width of the list when was defined a DataTemplate for the ItemTemplate of the list. For example, the Xaml code below: … produces this: It should be noted that despite <Grid HorizontalAlignment=”Stretch”>, … Continue reading “C# – How to make items of ListView fill the entire list width”

C# – Binding the XAML controls DatePicker and TimePicker to a variable of type DateTime

  Since Windows 8.1 is available the DatePicker and TimePicker controls. These controls allow an application to easily choose a date or time. Yet, as the DatePicker.Date property is of type DateTimeOffset and TimePicker.Time property is of type TimeSpan, they can not be binded directly to a variable or property of type DateTime. However, this … Continue reading “C# – Binding the XAML controls DatePicker and TimePicker to a variable of type DateTime”