ItemsControl with multiple DataTemplates for a viewmodel

You can create multiple ObservableCollections and then bind your ItemsSource to a CompositeCollection which joins those collections. Then in your XAML you can create different DataTemplates for the respective types using the DataType property which like styles gets automatically applied if it is placed in the resources. (You can also create the composite in XAML … Read more

How to implement INotifyDataErrorInfo in WPF 4.5? [closed]

Beside the very detailed description on MSDN about the Silverlight version of INotifyDataErrorInfo There are already some blog posts with samples how to use/implement it in WPF 4.5: WPF 4.5 – Asynchronous validation (original link no longer working) Wayback Link WPF 4.5 – Part 1 : Asynchronous data validation (the author has a nice series … Read more

How deterministic is floating point inaccuracy?

From what I understand you’re only guaranteed identical results provided that you’re dealing with the same instruction set and compiler, and that any processors you run on adhere strictly to the relevant standards (ie IEEE754). That said, unless you’re dealing with a particularly chaotic system any drift in calculation between runs isn’t likely to result … Read more

Iterating through an enumeration in Silverlight?

Or maybe strongly typed using linq, like this: public static T[] GetEnumValues<T>() { var type = typeof(T); if (!type.IsEnum) throw new ArgumentException(“Type ‘” + type.Name + “‘ is not an enum”); return ( from field in type.GetFields(BindingFlags.Public | BindingFlags.Static) where field.IsLiteral select (T)field.GetValue(null) ).ToArray(); } public static string[] GetEnumStrings<T>() { var type = typeof(T); if … Read more

Alternate background color in Listview XAML

I tried this and it works for me. <Window x:Class=”TryResponses.MainWindow” xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:vm=”clr-namespace:TryResponses” xmlns:system=”clr-namespace:System;assembly=mscorlib” Title=”MainWindow” Height=”350″ Width=”525″> <Window.Resources> <vm:MainWindowViewModel x:Key=”MainWindowViewModel” /> </Window.Resources> <Grid Background=”LightGray” DataContext=”{StaticResource MainWindowViewModel}”> <Grid.Resources> <Style TargetType=”ListViewItem”> <Style.Triggers> <Trigger Property=”ItemsControl.AlternationIndex” Value=”0″> <Setter Property=”Background” Value=”LightBlue” /> </Trigger> <Trigger Property=”ItemsControl.AlternationIndex” Value=”1″> <Setter Property=”Background” Value=”LightGray” /> </Trigger> </Style.Triggers> </Style> <DataTemplate DataType=”system:String”> <!– put your data template … Read more

Can I have one Style with multiple TargetType in WPF?

No you cannot, however I often create a style for a shared base class such as FrameworkElement, and then create my individual control styles that are BasedOn the base style <Style TargetType=”{x:Type FrameworkElement}”> <!– Shared Setters –> </Style> <Style TargetType=”{x:Type TextBlock}” BasedOn=”{StaticResource {x:Type FrameworkElement}}” /> <Style TargetType=”{x:Type Label}” BasedOn=”{StaticResource {x:Type FrameworkElement}}” /> <Style TargetType=”{x:Type Button}” … Read more

tech