Click here to Skip to main content
11,715,491 members (85,240 online)
Click here to Skip to main content
Add your own
alternative version

WPF Business Application Series Part 2 of n - Form Notification Control that Binds to the IDataErrorInfo.Error Property

, 2 Apr 2008 CPOL 138.8K 1.8K 116
WPF VB.NET Business Application Form Notification control that binds to business entity objects that implement the IDataErrorInfo interface. The article also covers entity validation with the WPF 3.5 IDataErrorInfo interface.
wpflobparttwo.zip
WPFLOBPartTwo
Core
Core.csi
Core.vbproj.user
My Project
Settings.settings
Themes
WPF
Converters
Custom Controls
CustomToolBarButton
FormNotification
Time Display
Helpers
DemonstrationForms
Business Object
DemonstrationForms.csi
Forms
My Project
Settings.settings
WPFBusiessApplicationSample.suo
WPFBusinessApplicationSample
My Project
MyExtensions
Settings.settings
Resources
Images
Delete.png
DeleteDisabled.png
New.png
NewDisabled.png
rss.png
rss3d.png
Save.png
SaveDisabled.png
Skins
Metallic
OfficeBlack
OfficeBlue
WPFBusiessApplicationSample.csi
WPFBusiessApplicationSample.vbproj.user
WPFToolBarButtonSample.csi
wpflobparttwoupdated2-23-2008.zip
Core.csi
Core.vbproj.user
Settings.settings
DemonstrationForms.csi
Settings.settings
Settings.settings
Delete.png
DeleteDisabled.png
New.png
NewDisabled.png
rss.png
rss3d.png
Save.png
SaveDisabled.png
WPFBusiessApplicationSample.csi
WPFBusiessApplicationSample.vbproj.user
WPFToolBarButtonSample.csi
<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:Core_WPF="clr-namespace:Core.WPF">

    <Style TargetType="{x:Type Core_WPF:CustomToolBarButton}">
        <Style.Resources>
            <BooleanToVisibilityConverter x:Key="booleanToVisibilityConverter" />
            <Core_WPF:CustomToolBarButtonImageSourceConverter x:Key="customToolBarButtonImageSourceConverter" />

            <!-- Disabled Brushes are used for the Disabled look of each control -->
            <SolidColorBrush x:Key="DisabledForegroundBrush" Color="#888" />
            <SolidColorBrush x:Key="DisabledBackgroundBrush" Color="#EEE" />
            <SolidColorBrush x:Key="DisabledBorderBrush" Color="#AAA" />

            <!-- DefaultedBorderBrush is used to show KeyBoardFocus -->
            <LinearGradientBrush x:Key="DefaultedBorderBrush" EndPoint="0,1" StartPoint="0,0">
                <GradientStop Color="#777" Offset="0.0" />
                <GradientStop Color="#000" Offset="1.0" />
            </LinearGradientBrush>

        </Style.Resources>
        <Setter Property="BorderThickness" Value=".7" />
        <Setter Property="Padding" Value="5" />
        <Setter Property="IsTabStop" Value="False" />

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Core_WPF:CustomToolBarButton}">
                    <Border x:Name="Border" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                        <StackPanel Orientation="{Binding Path=ButtonLayout, RelativeSource={RelativeSource TemplatedParent}}">

                            <Image Stretch="None" VerticalAlignment="Center" Visibility="{Binding Path=ShowButtonImage, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource booleanToVisibilityConverter}}">

                                <Image.Source>
                                    <MultiBinding Converter="{StaticResource customToolBarButtonImageSourceConverter}">
                                        <Binding Path="IsEnabled" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="EnabledButtonImage" RelativeSource="{RelativeSource TemplatedParent}" />
                                        <Binding Path="DisabledButtonImage" RelativeSource="{RelativeSource TemplatedParent}" />
                                    </MultiBinding>
                                </Image.Source>
                            </Image>
                            <TextBlock x:Name="tbButtonText" Text="{Binding Path=ButtonText, RelativeSource={RelativeSource TemplatedParent}}" Visibility="{Binding Path=ShowButtonText, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource booleanToVisibilityConverter}}" />
                        </StackPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsKeyboardFocused" Value="true">
                            <Setter Property="BorderBrush" Value="{StaticResource DefaultedBorderBrush}" TargetName="Border" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Foreground" Value="{Binding Path=MouseOverForeground, RelativeSource={RelativeSource TemplatedParent}}" />
                            <Setter Property="BorderBrush" Value="{Binding Path=MouseOverBorder, RelativeSource={RelativeSource TemplatedParent}}" TargetName="Border" />
                            <Setter Property="BorderThickness" Value="0.7" TargetName="Border" />
                            <Setter Property="Background" TargetName="Border" Value="{Binding Path=MouseOverBackground, RelativeSource={RelativeSource TemplatedParent}}" />

                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Background" Value="{Binding Path=ButtonPressedBackground, RelativeSource={RelativeSource TemplatedParent}}" TargetName="Border" />
                            <Setter Property="BorderBrush" Value="{Binding Path=ButtonPressedBorder, RelativeSource={RelativeSource TemplatedParent}}" TargetName="Border" />
                            <Setter Property="BorderThickness" Value="0.7" TargetName="Border" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="true" />
                        <Trigger Property="IsEnabled" Value="false">
                            <!-- ToDo Developers you can uncomment these lines to give the look you want -->
                            <!--<Setter Property="Background" Value="{StaticResource DisabledBackgroundBrush}" TargetName="Border"/>
                            <Setter Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" TargetName="Border"/>-->
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}" />
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="ShowButtonImage" Value="True" />
                                <Condition Property="ShowButtonText" Value="True" />
                                <Condition Property="ButtonLayout" Value="Horizontal" />
                            </MultiTrigger.Conditions>
                            <MultiTrigger.Setters>
                                <Setter Property="Margin" TargetName="tbButtonText" Value="5,0,0,0" />
                            </MultiTrigger.Setters>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</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

Karl Shifflett
Architect Gayle Manufacturing Company
United States United States
Karl loves .NET, WPF, WCF, ASP.NET, VB.NET and C#.

Awards:

  • December 2008 VB.NET Code Project Article Award
  • 2009 Code Project MVP
  • 2008 Code Project MVP
  • 2008 Microsoft MVP - Client App Dev
  • December 2007 VB.NET Code Project Article Award
  • Gold Medal Winner at IBM's 1998 PROIV Programming Contest in Las Vegas
Click here to check out my Blog

Click here to learn about Mole 2010 debugging tool for Visual Studio 2010

Click here to read about XAML Power Toys

Just a grain of sand on the worlds beaches.


You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150901.1 | Last Updated 2 Apr 2008
Article Copyright 2008 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid