Click here to Skip to main content
15,886,742 members
Articles / Desktop Programming / WPF

An Animated "AlarmBar" Custom Control in WPF

Rate me:
Please Sign up or sign in to vote.
4.13/5 (6 votes)
22 Jul 2008CPOL6 min read 62.8K   1.5K   52  
Published WPF resources discussing control customization focus almost exclusively on editing local copies of ControlTemplates, while implementing and interacting with an actual Custom Control library requires a DIFFERENT set of techniques and reference syntax to be used
<UserControl x:Class="ClientUI.viewAlarmBarExamples"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:custom="clr-namespace:CustomControls;assembly=CustomControls"
    MinWidth="300">
    
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="resColors.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    
    <Grid>

        <StackPanel Name="panelAlarmBarExamples" >


            <!-- "Glass" bar with "Glow" animation style -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" CornerRadius="14" VisualStyle="Glass" AnimationStyle="GlowPulse"
                             OuterBorderBrush="WhiteSmoke" OuterBorderThickness="2" TextBlock.FontWeight="Bold" >
                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorCenterLineBackground}"
                          Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningCenterLineBackground}"
                          Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherCenterLineBackground}"
                          Foreground="{StaticResource brushOtherForegroundDark}" />
            </custom:AlarmBar>


            <!-- Default AlarmBar style -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" >
                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorSolidBackground}"
                              Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningSolidBackground}"
                              Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherSolidBackground}"
                              Foreground="{StaticResource brushOtherForegroundLight}" />
            </custom:AlarmBar>


            <!-- "Glass" bar style -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" VisualStyle="Glass" >
                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorFaintBackground}"
                          Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningFaintBackground}"
                          Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherFaintBackground}"
                          Foreground="{StaticResource brushOtherForegroundDark}" />
            </custom:AlarmBar>


            <!-- Default AlarmBar style ("blip" animation) -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" BorderThickness="0" CornerRadius="14" >

                <!-- demonstrate alternative, Xaml-based, enum reference -->
                <custom:AlarmBar.AnimationStyle>
                    <x:Static Member="custom:Animation.Blip" />
                </custom:AlarmBar.AnimationStyle>

                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorSolidBackground}"
                              Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningSolidBackground}"
                              Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherSolidBackground}"
                              Foreground="{StaticResource brushOtherForegroundLight}" />
            </custom:AlarmBar>


            <!-- "Etched" bar style (gradient background)  -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" VisualStyle="Etched"
                             Background="{StaticResource brushLightCenterBarBackground}" >
                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorLightCenterBackground}"
                          Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningLightCenterBackground}"
                          Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherLightCenterBackground}"
                          Foreground="{StaticResource brushOtherForegroundDark}" />
            </custom:AlarmBar>


            <!-- "Etched" bar with "GradientBlip" animation -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" CornerRadius="14" VisualStyle="Etched" AnimationStyle="GradientBlip">
                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorSolidBackground}"
                              Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningSolidBackground}"
                              Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherSolidBackground}"
                              Foreground="{StaticResource brushOtherForegroundLight}" />
            </custom:AlarmBar>


            <!-- "Glass" bar style -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" VisualStyle="Glass"
                             TextBlock.FontWeight="Bold" Background="#441E90FF" CornerRadius="0" >
                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorBrightBackground}"
                          Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningSolidBackground}"
                          Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherSolidBackground}"
                          Foreground="{StaticResource brushOtherForegroundLight}" />
            </custom:AlarmBar>


            <!-- "Etched" bar style -->

            <custom:AlarmBar Margin="2,6" VerticalAlignment="Top" VisualStyle="Etched"
                             Background="{StaticResource brushDarkenLeftSideBarBackground}" >
                <custom:Alarm Id="Error"   Background="{StaticResource brushErrorDarkenLeftSideBackground}"
                          Foreground="{StaticResource brushErrorForeground}" />
                <custom:Alarm Id="Warning" Background="{StaticResource brushWarningDarkenLeftSideBackground}"
                          Foreground="{StaticResource brushWarningForeground}" />
                <custom:Alarm Id="Other"   Background="{StaticResource brushOtherDarkenLeftSideBackground}"
                          Foreground="{StaticResource brushOtherForegroundLight}" />
            </custom:AlarmBar>


        </StackPanel>

    </Grid>
</UserControl>

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)


Written By
United States United States
I started out writing applications in C for a software development shop in Japan, did alot of work in C++/MFC, and some DirectX, at two Silicon Valley startups, and have been working with C# and Windows Forms ever since the release of .Net 1.0. Although I took a couple intro. to CS courses at CAL (Berkeley), my degree was actually in Asian Studies, and I learned to program "in the trenches". I was also the .Net evangelist at my most recent company, authoring internal white papers on .Net, sending out a weekly ".Net FYI" e-mail, conducting .Net training, and sweating the truth out of job candidates who claimed to have .Net experience (You'd be amazed at the number of Silicon Valley engineers who list "three years of C#" on their resumes, who are unable to explain how to hook up a simple event handler, or identify basic terms like "reflection", "attributes" -- or "Richter" and "Löwy").

Comments and Discussions