Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Catel - Part 4 of n: Unit testing with Catel

, 28 Jan 2011
This article explains how to write unit tests for MVVM using Catel.
Catel-04_01-unittesting.zip
src
Catel.Articles.04 - Unit testing
Models
Properties
Settings.settings
Resources
Images
add.png
delete.png
edit.png
group.png
UI
Data
Converters
ViewModels
Windows
Catel.Articles.04 - Unit testing.Test
Models
Properties
UI
ViewModels
Catel.Articles.Base
Data
Attributes
Properties
Settings.settings
Resources
Images
CatenaLogic.png
Preview.png
Run.png
ShowCode.png
UI
Controls
Helpers
ViewModels
Windows
Catel.Core
Attributes
ClassDiagrams
DataObjectBase.cd
SavableDataObjectBase.cd
Collections
Helpers
ComponentModel
Data
Attributes
Exceptions
Interfaces
Diagnostics
Extensions
Helpers
Exceptions
Helpers
IO
Exceptions
IoC
LLBLGen
Log4net
Appender
Extensions
Helpers
MVVM
Commands
Interfaces
Exceptions
Services
EventArgs
Exceptions
Interfaces
ViewModels
Attributes
Interfaces
Properties
Reflection
Exceptions
Extensions
Helpers
Runtime
Serialization
Attributes
Helpers
Security
Cryptography
Helpers
Catel.Examples.Models
Properties
Catel.Examples.PersonApplication
Properties
Settings.settings
Resources
Images
add.png
delete.png
edit.png
group.png
UI
Data
Converters
ViewModels
Windows
Catel.Examples.Silverlight
Properties
Resources
Images
add.png
delete.png
edit.png
group.png
UI
Data
Converters
Pages
ViewModels
Windows
Catel.Examples.Silverlight.Web
Catel.Examples.Silverlight.Web.csproj.user
ClientBin
Properties
Catel.FxCop
Catel.Silverlight
Diagnostics
log4net
Core
MVVM
Commands
Services
ViewModels
Properties
Catel.Core
Catel.Windows
Reflection
Themes
Generic
Assets
Old
Windows
Controls
Data
Converters
Helpers
Helpers
Catel.Silverlight.Test
Properties
Catel.Silverlight.Test.Web
Catel.Silverlight.Test.Web.csproj.user
ClientBin
Properties
Catel.snk
Catel.Templates.WpfApplication
Properties
Settings.settings
UI
Controls
ViewModels
Windows
Catel.Templates.WpfItemTemplates
Properties
UI
Controls
ViewModels
Windows
Catel.Test
Collections
Convert
Data
Helpers
IO
MVVM
UI
ViewModels
Properties
Reflection
Runtime
Serialization
Security
Cryptography
Test References
Catel.Windows.accessor
Windows
Data
Converters
Catel.vsmdi
Catel.Windows
ClassDiagrams
ViewModelBase.cd
Collections
Extensions
Helpers
MVVM
Commands
Services
Test
UI
ViewModels
Properties
Settings.settings
Resources
Images
Add.png
ClearOutput.png
Edit.png
Error.png
Loading.gif
Preview.png
Remove.png
Save.png
TipOfTheDay.png
Warning.png
Themes
Aero
ExpressionDark
Assets
Generic
Assets
Controls
Jetpack
Assets
background.png
Old
SunnyOrange
Assets
Windows
Controls
Extensions
LinkLabel
StackGrid
Data
Converters
Helpers
Documents
Extensions
Extensions
Helpers
Input
Markup
Media
Effects
EmptyEffect
EmptyEffect.fx
EmptyEffect.ps
EmptyEffect.fx
GrayscaleEffect
GrayscaleEffect.fx
GrayscaleEffect.ps
Extensions
Imaging
Extensions
Windows
DataWindow
TipOfTheDay
Local.testsettings
Settings.StyleCop
TraceAndTestImpact.testsettings
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:Catel.Windows.Controls"
	                xmlns:Converters="clr-namespace:Catel.Windows.Data.Converters"
                    xmlns:Effects="clr-namespace:Catel.Windows.Media.Effects">

	<!-- Converters -->
    <Converters:BooleanToGrayscaleConverter x:Key="BooleanToGrayscaleConverter" />
    <Converters:ContainsItemsConverter x:Key="ContainsItemsConverter" />
    <Converters:GetFirstValidationErrorConverter x:Key="GetFirstValidationErrorConverter" />
    <Converters:RoutedUICommandToToolTipConverter x:Key="RoutedUICommandToToolTipConverter" />
    <Converters:RoutedUICommandToContentConverter x:Key="RoutedUICommandToContentConverter" />

    <!-- Menu item -->
    <Style x:Key="DefaultMenuItemStyle" TargetType="{x:Type MenuItem}" BasedOn="{StaticResource {x:Type MenuItem}}">
        <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Command, Converter={StaticResource RoutedUICommandToToolTipConverter}}" />
		<Setter Property="ToolTipService.IsEnabled" Value="{Binding RelativeSource={RelativeSource Self}, Path=ToolTip, Converter={StaticResource ContainsItemsConverter}}" />
		<Setter Property="Header" Value="{Binding RelativeSource={RelativeSource Self}, Path=Command, Converter={StaticResource RoutedUICommandToContentConverter}}" />
	</Style>

    <!-- ToggleButton -->
    <Style x:Key="DefaultToggleButtonStyle" TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
        <Setter Property="Margin" Value="{DynamicResource Margin.Button}" />
    </Style>

    <!-- DropDownButton -->
    <Style x:Key="DefaultDropDownButtonStyle" TargetType="{x:Type Controls:DropDownButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
        <Setter Property="Margin" Value="{DynamicResource Margin.Button}" />

        <!-- Grayscale effect when disabled -->
        <Setter Property="Effect">
            <Setter.Value>
                <Effects:GrayscaleEffect DesaturationFactor="{Binding RelativeSource={RelativeSource AncestorType={x:Type Controls:DropDownButton}}, Path=IsEnabled, Converter={StaticResource BooleanToGrayscaleConverter}}" />
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ImageDropDownButtonStyle" TargetType="{x:Type Controls:DropDownButton}" BasedOn="{StaticResource DefaultDropDownButtonStyle}">
        <Setter Property="Width" Value="{DynamicResource Size.Image.Medium}" />
        <Setter Property="Height" Value="{DynamicResource Size.Image.Medium}" />
    </Style>

    <!-- Buttons -->
	<Style x:Key="DefaultButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource {x:Type Button}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button}" />
		<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Command, Converter={StaticResource RoutedUICommandToToolTipConverter}}" />
		<Setter Property="ToolTipService.IsEnabled" Value="{Binding RelativeSource={RelativeSource Self}, Path=ToolTip, Converter={StaticResource ContainsItemsConverter}}" />
		<Setter Property="Content" Value="{Binding RelativeSource={RelativeSource Self}, Path=Command, Converter={StaticResource RoutedUICommandToContentConverter}}" />

		<!-- Due to a bug, adjust the error template (see http://stackoverflow.com/questions/321327/how-do-i-get-rid-of-the-red-rectangle-when-my-wpf-binding-validation-has-failed-a) -->
		<Setter Property="Validation.ErrorTemplate">
			<Setter.Value>
				<ControlTemplate>
					<ControlTemplate.Resources>
						<Converters:BooleanToHidingVisibilityConverter x:Key="BooleanToHidingVisibilityConverter" />
					</ControlTemplate.Resources>
					<DockPanel LastChildFill="True">
						<Border BorderThickness="1" BorderBrush="Red" 
								Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource BooleanToHidingVisibilityConverter}}">
							<AdornedElementPlaceholder x:Name="placeholder" />
						</Border>
					</DockPanel>
				</ControlTemplate>
			</Setter.Value>
		</Setter>

        <!-- Grayscale effect when disabled -->
        <Setter Property="Effect">
            <Setter.Value>
                <Effects:GrayscaleEffect DesaturationFactor="{Binding RelativeSource={RelativeSource AncestorType={x:Type Button}}, Path=IsEnabled, Converter={StaticResource BooleanToGrayscaleConverter}}" />
            </Setter.Value>
        </Setter>
    </Style>
    
	<!-- Very large image buttons -->
    <Style x:Key="VeryLargeImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
		<Setter Property="Width" Value="{DynamicResource Size.Image.VeryLarge}" />
		<Setter Property="Height" Value="{DynamicResource Size.Image.VeryLarge}" />
	</Style>

    <Style x:Key="VeryLargeRightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource VeryLargeImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

	<!-- Large image buttons -->
    <Style x:Key="LargeImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
		<Setter Property="Width" Value="{DynamicResource Size.Image.Large}" />
		<Setter Property="Height" Value="{DynamicResource Size.Image.Large}" />
	</Style>

	<Style x:Key="LargeRightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource LargeImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

	<Style x:Key="LargeSideImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource LargeImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button}" />
	</Style>

	<!-- Medium image buttons -->
    <Style x:Key="MediumImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
		<Setter Property="Width" Value="{DynamicResource Size.Image.Medium}" />
		<Setter Property="Height" Value="{DynamicResource Size.Image.Medium}" />
    </Style>

    <Style x:Key="ImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumImageButtonStyle}" />

    <Style x:Key="MediumRightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumImageButtonStyle}">
        <Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
        <Setter Property="HorizontalAlignment" Value="Right" />
    </Style>

    <Style x:Key="MediumTopRightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumRightAlignedImageButtonStyle}">
        <Setter Property="VerticalAlignment" Value="Top" />
    </Style>

    <Style x:Key="RightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumRightAlignedImageButtonStyle}">
    </Style>

    <Style x:Key="TopRightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumTopRightAlignedImageButtonStyle}">
    </Style>

    <Style x:Key="MediumLeftAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumImageButtonStyle}">
        <Setter Property="Margin" Value="{DynamicResource Margin.Button.LeftAligned}" />
        <Setter Property="HorizontalAlignment" Value="Left" />
    </Style>

    <Style x:Key="MediumTopLeftAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumLeftAlignedImageButtonStyle}">
        <Setter Property="VerticalAlignment" Value="Top" />
    </Style>

    <Style x:Key="LeftAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumLeftAlignedImageButtonStyle}">
    </Style>

    <Style x:Key="TopLeftAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource MediumTopLeftAlignedImageButtonStyle}">
    </Style>    
    
    <!-- Toolbar image buttons (small) -->
    <Style x:Key="ToolBarImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
		<Setter Property="Width" Value="{DynamicResource Size.Image.Small}" />
		<Setter Property="Height" Value="{DynamicResource Size.Image.Small}" />
	</Style>

	<Style x:Key="RightAlignedToolBarImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource ToolBarImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

	<Style x:Key="TopRightAlignedToolBarImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource RightAlignedToolBarImageButtonStyle}">
		<Setter Property="VerticalAlignment" Value="Top" />
	</Style>

	<Style x:Key="LeftAlignedToolBarImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource ToolBarImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.LeftAligned}" />
		<Setter Property="HorizontalAlignment" Value="Left" />
	</Style>

	<!-- Small image buttons -->
	<Style x:Key="SmallImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource ToolBarImageButtonStyle}" />

	<Style x:Key="SmallRightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource SmallImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

	<Style x:Key="SmallLeftAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource SmallImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.LeftAligned}" />
		<Setter Property="HorizontalAlignment" Value="Left" />
	</Style>

	<!-- Very small image buttons -->
    <Style x:Key="VerySmallImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
		<Setter Property="Width" Value="{DynamicResource Size.Image.VerySmall}" />
		<Setter Property="Height" Value="{DynamicResource Size.Image.VerySmall}" />
	</Style>

	<Style x:Key="VerySmallRightAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource VerySmallImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

	<Style x:Key="VerySmallLeftAlignedImageButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource VerySmallImageButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.LeftAligned}" />
		<Setter Property="HorizontalAlignment" Value="Left" />
	</Style>

	<!-- Fixed size buttons -->
    <Style x:Key="LargeFixedSizeButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
        <Setter Property="MinWidth" Value="125" />
        <Setter Property="MinHeight" Value="{DynamicResource Size.MinHeight}" />
    </Style>

    <Style x:Key="FixedSizeButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource DefaultButtonStyle}">
		<Setter Property="MinWidth" Value="100" />
		<Setter Property="MinHeight" Value="{DynamicResource Size.MinHeight}" />
	</Style>

    <Style x:Key="LeftAlignedLargeFixedSizeButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource LargeFixedSizeButtonStyle}">
        <Setter Property="Margin" Value="{DynamicResource Margin.Button.LeftAligned}" />
        <Setter Property="HorizontalAlignment" Value="Left" />
    </Style>

    <Style x:Key="LeftAlignedFixedSizeButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource FixedSizeButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.LeftAligned}" />
		<Setter Property="HorizontalAlignment" Value="Left" />
	</Style>

	<Style x:Key="RightAlignedLargeFixedSizeButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource LargeFixedSizeButtonStyle}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

    <Style x:Key="RightAlignedFixedSizeButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource FixedSizeButtonStyle}">
        <Setter Property="Margin" Value="{DynamicResource Margin.Button.RightAligned}" />
        <Setter Property="HorizontalAlignment" Value="Right" />
    </Style>

    <Style x:Key="BottomRightAlignedFixedSizeButtonStyle" TargetType="{x:Type Button}" BasedOn="{StaticResource RightAlignedFixedSizeButtonStyle}">
		<Setter Property="Button.VerticalAlignment" Value="Bottom" />
	</Style>

	<!-- Label -->
	<Style x:Key="DefaultLabelStyle" TargetType="{x:Type Label}" BasedOn="{StaticResource {x:Type Label}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Label}" />
		<Setter Property="Padding" Value="{DynamicResource Padding.Label}" />
    </Style>
	
	<Style x:Key="ImportantTextLabelStyle" TargetType="{x:Type Label}" BasedOn="{StaticResource DefaultLabelStyle}">
		<Setter Property="Foreground" Value="Red" />
		<Setter Property="FontWeight" Value="Bold" />
	</Style>

	<!-- TextBlock -->
	<Style x:Key="DefaultTextBlockStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource {x:Type TextBlock}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.TextBlock}" />
		<Setter Property="VerticalAlignment" Value="Center" />
	</Style>

	<Style x:Key="CaptionTextBlockStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlockStyle}">
		<Setter Property="FontSize" Value="14" />
	</Style>

	<Style x:Key="RightAlignedTextBlockStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlockStyle}">
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

	<Style x:Key="BoldTextBlockStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlockStyle}">
		<Setter Property="FontWeight" Value="Bold" />
	</Style>

	<Style x:Key="HeadingTextBlockStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlockStyle}">
		<Setter Property="FontSize" Value="14" />
		<Setter Property="FontWeight" Value="Bold" />
	</Style>

	<Style x:Key="ViewTextBlockStyle" TargetType="{x:Type TextBlock}" BasedOn="{StaticResource DefaultTextBlockStyle}">
		<Setter Property="IsEnabled" Value="false" />
		<Setter Property="Background" Value="LightGray" />
	</Style>

	<!-- ListBox -->
	<Style x:Key="DefaultListBoxStyle" TargetType="{x:Type ListBox}" BasedOn="{StaticResource {x:Type ListBox}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
	</Style>

	<!-- GroupBox -->
	<Style x:Key="DefaultGroupBoxStyle" TargetType="{x:Type GroupBox}" BasedOn="{StaticResource {x:Type GroupBox}}">
        <Setter Property="BorderBrush" Value="#888" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Margin" Value="{DynamicResource Margin.GroupBox}" />
	</Style>

    <!-- TextBox -->
	<Style x:Key="DefaultTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource {x:Type TextBox}}">
		<Setter Property="MinHeight" Value="{DynamicResource Size.MinHeight}" />
		<Setter Property="Padding" Value="{DynamicResource Padding.TextBox}" />
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
		<Setter Property="HorizontalAlignment" Value="Stretch" />

        <!-- Due to a bug, adjust the error template (see http://stackoverflow.com/questions/321327/how-do-i-get-rid-of-the-red-rectangle-when-my-wpf-binding-validation-has-failed-a) -->
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <ControlTemplate.Resources>
                        <Converters:BooleanToHidingVisibilityConverter x:Key="BooleanToHidingVisibilityConverter" />
                    </ControlTemplate.Resources>
                    <DockPanel LastChildFill="True">
                        <Border BorderThickness="1" BorderBrush="Red" 
								Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource BooleanToHidingVisibilityConverter}}">
                            <AdornedElementPlaceholder x:Name="placeholder" />
                        </Border>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>        
        
		<!-- Show errors as tooltip -->
		<Style.Triggers>
			<Trigger Property="Validation.HasError" Value="true">
				<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource GetFirstValidationErrorConverter}}" />
			</Trigger>
		</Style.Triggers>
	</Style>

	<Style x:Key="SmallTextBoxStyle" TargetType="{x:Type TextBox}" BasedOn="{StaticResource DefaultTextBoxStyle}">
		<Setter Property="Width" Value="60"/>
	</Style>

	<!-- PasswordBox -->
	<Style x:Key="DefaultPasswordBoxStyle" TargetType="{x:Type PasswordBox}" BasedOn="{StaticResource {x:Type PasswordBox}}">
		<Setter Property="MinHeight" Value="{DynamicResource Size.MinHeight}" />
		<Setter Property="Padding" Value="{DynamicResource Padding.TextBox}" />
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />

        <!-- Due to a bug, adjust the error template (see http://stackoverflow.com/questions/321327/how-do-i-get-rid-of-the-red-rectangle-when-my-wpf-binding-validation-has-failed-a) -->
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <ControlTemplate.Resources>
                        <Converters:BooleanToHidingVisibilityConverter x:Key="BooleanToHidingVisibilityConverter" />
                    </ControlTemplate.Resources>
                    <DockPanel LastChildFill="True">
                        <Border BorderThickness="1" BorderBrush="Red" 
								Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource BooleanToHidingVisibilityConverter}}">
                            <AdornedElementPlaceholder x:Name="placeholder" />
                        </Border>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <!-- Show errors as tooltip -->
		<Style.Triggers>
			<Trigger Property="Validation.HasError" Value="true">
				<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource GetFirstValidationErrorConverter}}" />
			</Trigger>
		</Style.Triggers>
	</Style>

	<!-- Slider -->
	<Style x:Key="DefaultSliderStyle" TargetType="{x:Type Slider}" BasedOn="{StaticResource {x:Type Slider}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
	</Style>

	<!-- Progress bar -->
	<Style x:Key="DefaultProgressBarStyle" TargetType="{x:Type ProgressBar}" BasedOn="{StaticResource {x:Type ProgressBar}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
	</Style>

	<!-- TabControl -->
	<Style x:Key="DefaultTabControlStyle" TargetType="{x:Type TabControl}" BasedOn="{StaticResource {x:Type TabControl}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
	</Style>

	<!-- CheckBox -->
	<Style x:Key="DefaultCheckBoxStyle" TargetType="{x:Type CheckBox}" BasedOn="{StaticResource {x:Type CheckBox}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.CheckBox}" />
		<Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="Width" Value="Auto" />
        <Setter Property="HorizontalAlignment" Value="Left" />

        <!-- Due to a bug, adjust the error template (see http://stackoverflow.com/questions/321327/how-do-i-get-rid-of-the-red-rectangle-when-my-wpf-binding-validation-has-failed-a) -->
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <ControlTemplate.Resources>
                        <Converters:BooleanToHidingVisibilityConverter x:Key="BooleanToHidingVisibilityConverter" />
                    </ControlTemplate.Resources>
                    <DockPanel LastChildFill="True">
                        <Border BorderThickness="1" BorderBrush="Red" 
								Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource BooleanToHidingVisibilityConverter}}">
                            <AdornedElementPlaceholder x:Name="placeholder" />
                        </Border>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <!-- Show errors as tooltip -->
		<Style.Triggers>
			<Trigger Property="Validation.HasError" Value="true">
				<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource GetFirstValidationErrorConverter}}" />
			</Trigger>
		</Style.Triggers>
	</Style>

	<!-- RadioButton -->
	<Style x:Key="DefaultRadioButtonStyle" TargetType="{x:Type RadioButton}" BasedOn="{StaticResource {x:Type RadioButton}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.RadioButton}" />
		<Setter Property="VerticalAlignment" Value="Center" />

        <!-- Due to a bug, adjust the error template (see http://stackoverflow.com/questions/321327/how-do-i-get-rid-of-the-red-rectangle-when-my-wpf-binding-validation-has-failed-a) -->
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <ControlTemplate.Resources>
                        <Converters:BooleanToHidingVisibilityConverter x:Key="BooleanToHidingVisibilityConverter" />
                    </ControlTemplate.Resources>
                    <DockPanel LastChildFill="True">
                        <Border BorderThickness="1" BorderBrush="Red" 
								Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource BooleanToHidingVisibilityConverter}}">
                            <AdornedElementPlaceholder x:Name="placeholder" />
                        </Border>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <!-- Show errors as tooltip -->
		<Style.Triggers>
			<Trigger Property="Validation.HasError" Value="true">
				<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource GetFirstValidationErrorConverter}}" />
			</Trigger>
		</Style.Triggers>
	</Style>

    <!-- RadioButtonEx -->
    <Style x:Key="DefaultRadioButtonExStyle" TargetType="{x:Type Controls:RadioButtonEx}" BasedOn="{StaticResource DefaultRadioButtonStyle}">
        <!-- Style copied from .NET Framework radiobutton -->
    </Style>

    <!-- ListView -->
	<Style x:Key="DefaultListViewStyle" TargetType="{x:Type ListView}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
	</Style>

	<!-- ComboBox -->
	<Style x:Key="DefaultComboBoxStyle" TargetType="{x:Type ComboBox}" BasedOn="{StaticResource {x:Type ComboBox}}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
		<Setter Property="MinWidth" Value="120" />

        <!-- Due to a bug, adjust the error template (see http://stackoverflow.com/questions/321327/how-do-i-get-rid-of-the-red-rectangle-when-my-wpf-binding-validation-has-failed-a) -->
        <Setter Property="Validation.ErrorTemplate">
            <Setter.Value>
                <ControlTemplate>
                    <ControlTemplate.Resources>
                        <Converters:BooleanToHidingVisibilityConverter x:Key="BooleanToHidingVisibilityConverter" />
                    </ControlTemplate.Resources>
                    <DockPanel LastChildFill="True">
                        <Border BorderThickness="1" BorderBrush="Red" 
								Visibility="{Binding ElementName=placeholder, Mode=OneWay, Path=AdornedElement.IsVisible, Converter={StaticResource BooleanToHidingVisibilityConverter}}">
                            <AdornedElementPlaceholder x:Name="placeholder" />
                        </Border>
                    </DockPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>

        <!-- Show errors as tooltip -->
		<Style.Triggers>
			<Trigger Property="Validation.HasError" Value="true">
				<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource GetFirstValidationErrorConverter}}" />
			</Trigger>
		</Style.Triggers>
	</Style>


    <!-- Grid -->
	<Style x:Key="WindowGridStyle" TargetType="{x:Type Grid}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
	</Style>

	<!-- Wrap panel -->
	<Style x:Key="ButtonsWrapPanelStyle" TargetType="{x:Type WrapPanel}">
		<Setter Property="Margin" Value="{DynamicResource Margin.Default}" />
	</Style>

	<Style x:Key="RightAlignedButtonsWrapPanelStyle" TargetType="{x:Type WrapPanel}" BasedOn="{StaticResource ButtonsWrapPanelStyle}">
		<Setter Property="HorizontalAlignment" Value="Right" />
	</Style>

	<Style x:Key="LeftAlignedButtonsWrapPanelStyle" TargetType="{x:Type WrapPanel}" BasedOn="{StaticResource ButtonsWrapPanelStyle}">
		<Setter Property="HorizontalAlignment" Value="Left" />
	</Style>

	<!-- DocumentViewer -->
	<Style x:Key="DefaultDocumentViewerStyle" TargetType="{x:Type DocumentViewer}" BasedOn="{StaticResource {x:Type DocumentViewer}}">
		<!--<Setter Property="Background" Value="AliceBlue" />-->
	</Style>
	
	<!-- ScrollViewer -->
	<!--<Style x:Key="DefaultScrollViewerStyle" TargetType="{x:Type ScrollViewer}" BasedOn="{StaticResource {x:Type ScrollViewer}}">
        <Setter Property="Controls:ScrollViewerProperties.FixScrolling" Value="True" />
	</Style>-->

	<!-- 
	
		CUSTOM COMPANY CONTROLS 
	
	    Custom company controls should be declared below so they can be easily found.
	
	-->

</ResourceDictionary>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Geert van Horrik
Software Developer CatenaLogic
Netherlands Netherlands
I am Geert van Horrik, and I have studied Computer Science in the Netherlands.
 
I love to write software using .NET (especially the combination of WPF and C#). I am also the lead developer of Catel, an open-source application development framework for WPF, Silverlight, WP7 and WinRT with the focus on MVVM.
 
I have my own company since January 1st 2007, called CatenaLogic. This company develops commercial and non-commercial software.
 
To download (or buy) applications I have written, visit my website: http://www.catenalogic.com
Follow on   Twitter

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 28 Jan 2011
Article Copyright 2011 by Geert van Horrik
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid