Click here to Skip to main content
13,053,994 members (59,470 online)
Click here to Skip to main content

Stats

155.8K views
1.9K downloads
116 bookmarked
Posted 22 Feb 2008

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

, 2 Apr 2008
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
Core
Core.csi
Core.vbproj.user
My Project
Themes
WPF
Converters
Custom Controls
CustomToolBarButton
FormNotification
Time Display
Helpers
DemonstrationForms
Business Object
DemonstrationForms.csi
Forms
My Project
WPFBusiessApplicationSample.suo
WPFBusinessApplicationSample
My Project
MyExtensions
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
Core.csi
Core.vbproj.user
DemonstrationForms.csi
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 Infragistics
United States United States

I’m a passionate Platform Architect at Infragistics.


I’m a long-time WPF-Prism fanatic who enjoys writing developer tools and line of business applications.


My current front end passions are: XAML platforms (Xamarin.Forms, Xamarin, UWP, and WPF), Electron, ES2015 (ES6), Node.js, Aurelia, and AngularJS (Angular 1.5.x).


For the back end I use what is appropriate for the project: SQL Server and ASP.NET WebAPI, MongoDB, Express, Azure, Firebase, etc.


I am very pragmatic software engineer and strive to write simple, maintainable, and testable code. Simple code allows for solving complex problems in a maintainable way.


My Blog


My Github Repros


My YouTube Videos


Just a grain of sand on the worlds beaches.


You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 2 Apr 2008
Article Copyright 2008 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid