当前位置:编程学习 > C#/ASP.NET >>

Silverlight中实现带CheckBox的多选下拉框(源码下载)

第一种格式:使用DisplayPath和SelectedValuePath,使用自定义分隔符 "|"

第二种格式:

这个版本对于我们的项目应用已经够了,但是其中还有一个问题没有解决 SelectedValue的双向绑定有些问题、从源端到控件的绑定还没有处理

好了下面我们来看代码CheckedComboBox.cs

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Controls.Primitives;
using System.Windows.Interop;
using System.Windows.Data;

namespace SL.UI.Form
{
    [TemplatePart(Name = "DropDownToggle", Type = typeof(ToggleButton)),
    TemplateVisualState(Name = "InvalidFocused", GroupName = "ValidationStates"),
    TemplatePart(Name = "ContentPresenter", Type = typeof(ContentPresenter)),
    TemplatePart(Name = "Popup", Type = typeof(Popup)),
    TemplatePart(Name = "ContentPresenterBorder", Type = typeof(FrameworkElement)),
    TemplatePart(Name = "ScrollViewer", Type = typeof(ScrollViewer)),
    TemplateVisualState(Name = "Normal", GroupName = "CommonStates"),
    TemplateVisualState(Name = "MouseOver", GroupName = "CommonStates"),
    TemplateVisualState(Name = "Disabled", GroupName = "CommonStates"),
    TemplateVisualState(Name = "Unfocused", GroupName = "FocusStates"),
    TemplateVisualState(Name = "Focused", GroupName = "FocusStates"),
    TemplateVisualState(Name = "FocusedDropDown", GroupName = "FocusStates"),
    TemplateVisualState(Name = "Valid", GroupName = "ValidationStates"),
    TemplateVisualState(Name = "InvalidUnfocused", GroupName = "ValidationStates")]
    public class CheckedComboBox : ItemsControl
    {
        private const string ElementContentPresenterBorderName = "ContentPresenterBorder";
        private const string ElementContentPresenterName = "ContentPresenter";
        private const string ElementDropDownToggleName = "DropDownToggle";
        private const string ElementPopupName = "Popup";
        private const string ElementItemsPresenterName = "ItemsPresenter";

        private ContentPresenter ElementContentPresenter;
        private FrameworkElement ElementContentPresenterBorder;
        private ListBox ElementItemsPresenter;
        private FrameworkElement ElementPopupChild;
        private ToggleButton ElementDropDownToggle;

        private Canvas ElementOutsidePopup;
        private Popup ElementPopup;
        private Canvas ElementPopupChildCanvas;
        private bool _isMouseOverMain;
        private bool _isMouseOverPopup;

        #region DependencyProperty
        public static readonly DependencyProperty IsDropDownOpenProperty;
        public bool IsDropDownOpen
        {
            get
            {
                return (bool)base.GetValue(IsDropDownOpenProperty);
            }
            set
            {
                base.SetValue(IsDropDownOpenProperty, value);
            }
        }
        public static readonly DependencyProperty MaxDropDownHeightProperty;
        public double MaxDropDownHeight
        {
            get
            {
                return (double)base.GetValue(MaxDropDownHeightProperty);
            }
            set
            {
                base.SetValue(MaxDropDownHeightProperty, value);
            }
        }
        public static readonly DependencyProperty SelectedValueProperty;
        public object SelectedValue
        {
            get { return base.GetValue(SelectedValueProperty); }
            set { base.SetValue(SelectedValueProperty, value); }
        }
        public static readonly DependencyProperty SelectedValuePathProperty;
        public string SelectedValuePath
        {
            get { return (string)base.GetValue(SelectedValuePathProperty); }
            set { base.SetValue(SelectedValuePathProperty, value); }
        }
        public static readonly DependencyProperty SeparatorCharProperty;
        public string SeparatorChar
        {
            get { return (string)base.GetValue(SeparatorCharProperty); }
            set { base.SetValue(SeparatorCharProperty, value); }
        }
        public static readonly DependencyProperty SelectionModeProperty;
        public SelectionMode SelectionMode
        {
            get { return (SelectionMode)base.GetValue(SelectionModeProperty); }
            set { base.SetValue(SelectionModeProperty, value); }
        }
        #endregion

        #region Events
        public event EventHandler DropDownClosed;
        public event EventHandler DropDownOpened;
        public event SelectionChangedEventHandler SelectionChanged;
        #endregion

        #region DependencyPropertyChangedCallback
        private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckedComboBox box = (CheckedComboBox)d;
            box.OnIsDropDownOpenChanged((bool)e.NewValue);
        }
        private static void OnMaxDropDownHeightChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            ((CheckedComboBox)d).OnMaxDropDownHeightChanged((double)e.NewValue);
        }
        private static void OnSelectedValuePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckedComboBox ccb = d as CheckedComboBox;
            if (e.NewValue != null && !e.NewValue.Equals(e.OldValue))
            { ccb.OnSelectedValueChanged(e.NewValue); }

        }
        private static void OnSelectedValuePathPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
        }
        private static void OnSeparatorCharPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {

        }
        private static void OnSelectionModePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            CheckedComboBox ccb = d as CheckedComboBox;
            if (ccb != null)
            {
                ccb.ElementItemsPresenter.SelectionMode = (SelectionMode)e.NewValue;
            }
        }
        #endregion

        static CheckedComboBox()
        {
            IsDropDownOpenProperty = DependencyProperty.Register("IsDropDownOpen", typeof(bool), typeof(CheckedComboBox), new PropertyMetadata(new PropertyChangedCallback(OnIsDropDownOpenChanged)));
            MaxDropDownHeightProperty = DependencyProperty.Register("MaxDropDownHeight", typeof(double), typeof(CheckedComboBox), new PropertyMetadata((double)1.0 / (double)0.0, new PropertyChangedCallback(OnMaxDropDownHeightChanged)));
            SelectedValueProperty = DependencyProperty.Register("SelectedValue", typeof(object), typeof(CheckedComboBox), new PropertyMetadata(null, new PropertyChangedCallback(OnSelectedValuePropertyChanged)));
            SelectedValuePathProperty = DependencyProperty.Register("SelectedValuePath", typeof(string), typeof(CheckedComboBox), new PropertyMetadata(string.Empty, new PropertyChangedCallback(OnSelectedValuePathPropertyChanged)));
            SeparatorCharProperty = DependencyProperty.Register("SeparatorChar", typeof(string), typeof(CheckedComboBox), new PropertyMetadata(",", new PropertyChangedCallback(OnSeparatorCharPropertyChanged)));
            SelectionModeProperty = DependencyProperty.Register("SelectionMode", typeof(SelectionMode), typeof(CheckedComboBox), new PropertyMetadata(SelectionMode.Multiple, new PropertyChangedCallback(OnSelectionModePropertyChanged)));
        }
        public CheckedComboBox()
            : base()
        {
            this.DefaultStyleKey = typeof(CheckedComboBox);
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.IsDropDownOpen = false;
            this.ElementDropDownToggle = base.GetTemplateChild(ElementDropDownToggleName) as ToggleButton;
            this.ElementPopup = base.GetTemplateChild(ElementPopupName) as Popup;
            this.ElementContentPresenterBorder = base.GetTemplateChild(ElementContentPresenterBorderName) as FrameworkElement;
            this.ElementContentPresenter = base.GetTemplateChild(ElementContentPresenterName) as ContentPresenter;
            this.ElementItemsPresenter = base.GetTemplateChild(ElementItemsPresenterName) as ListBox;

            if (this.ElementItemsPresenter != null)
            {
                this.ElementItemsPresenter.SelectionChanged += new SelectionChangedEventHandler(ElementItemsPresenter_SelectionChanged);
                OnSelectedValueChanged(this.SelectedValue);
            }
            if (this.ElementDropDownToggle != null)
            {
                this.ElementDropDownToggle.IsTabStop = false;
                this.ElementDropDownToggle.Click += new RoutedEventHandler(this.ElementDropDownToggle_Click);
            }
            if (this.ElementPopup != null)
            {
                this.ElementPopupChild = this.ElementPopup.Child as FrameworkElement;
                this.ElementOutsidePopup = new Canvas();
            }
            else
            {
                this.ElementPopupChild = null;
                this.ElementOutsidePopup = null;
            }
            if (this.ElementOutsidePopup != null)
            {
                this.ElementOutsidePopup.Background = new SolidColorBrush(Colors.Transparent);
                this.ElementOutsidePopup.MouseLeftButtonDown += new MouseButtonEventHandler(this.ElementOutsidePopup_MouseLeftButtonDown);
            }
            KeyEventHandler handler = delegate(object sender, KeyEventArgs e)
            {
                this.OnKeyDown(e);
            };
            base.KeyDown += handler;
            base.SizeChanged += new SizeChangedEventHandler(this.ElementPopupChild_SizeChanged);
            if (this.ElementPopupChild != null)
            {
                this.ElementPopupChild.KeyDown += handler;
                this.ElementPopupChild.MouseEnter += new MouseEventHandler(this.ElementPopupChild_MouseEnter);
                this.ElementPopupChild.MouseLeave += new MouseEventHandler(this.ElementPopupChild_MouseLeave);
                this.ElementPopupChild.SizeChanged += new SizeChangedEventHandler(this.ElementPopupChild_SizeChanged);
                this.ElementPopupChildCanvas = new Canvas();
            }
            else
            {
                this.ElementPopupChildCanvas = null;
            }
            if ((this.ElementPopupChildCanvas != null) && (this.ElementOutsidePopup != null))
            {
                this.ElementPopup.Child = this.ElementPopupChildCanvas;
                this.ElementPopupChildCanvas.Children.Add(this.ElementOutsidePopup);
                this.ElementPopupChildCanvas.Children.Add(this.ElementPopupChild);
            }
            this.ChangeVisualState(false);
        }
        private void OnSelectedValueChanged(object selectedValue)
        {
            //未实现
            return;
            if (this.ElementItemsPresenter != null && !string.IsNullOrEmpty(this.SeparatorChar))
            {
                string valuePath = this.SelectedValuePath;
                if (!string.IsNullOrEmpty(valuePath))
                {
                    string[] array = selectedValue.ToString().Split(new string[] { this.SeparatorChar }, StringSplitOptions.None);
                    foreach (var item in this.ElementItemsPresenter.Items)
                    {
                        ListBoxItem lbi = this.ElementItemsPresenter.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;

                        if (lbi != null)
                        {
                            Binding binding = new Binding(valuePath) { Source = item };
                            ContentControl temp = new ContentControl();
                            temp.SetBinding(ContentControl.ContentProperty, binding);

                            if (temp.Content != null)
                            {
                                foreach (var s in array)
                                {
                                    if (s.Equals(temp.Content.ToString()))
                                    {
                                        lbi.IsSelected = true; continue;
                                    }
                                }
                            }
                            temp.ClearValue(ContentControl.ContentProperty);
                        }
                    }
                }
            }
        }
        private void OnMaxDropDownHeightChanged(double newValue)
        {
            this.ArrangePopup();
            this.ChangeVisualState();
        }
        private void ArrangePopup()
        {
            if (((this.ElementPopup != null) && (this.ElementPopupChild != null)) && ((this.ElementContentPresenterBorder != null) && (this.ElementOutsidePopup != null)))
            {
                Content content = Application.Current.Host.Content;
                double actualWidth = content.ActualWidth;
                double actualHeight = content.ActualHeight;
                double num3 = this.ElementPopupChild.ActualWidth;
                double num4 = this.ElementPopupChild.ActualHeight;
                if ((actualHeight != 0.0) && (actualWidth != 0.0))
                {
                    GeneralTransform transform = null;
                    try
                    {
                        transform = this.ElementContentPresenterBorder.TransformToVisual(null);
                    }
                    catch
                    {
                        this.IsDropDownOpen = false;
                    }
                    if (transform != null)
                    {
                        Point point = new Point(0.0, 0.0);
                        Point point2 = new Point(1.0, 0.0);
                        Point point3 = new Point(0.0, 1.0);
                        Point point4 = transform.Transform(point);
                        Point point5 = transform.Transform(point2);
                        Point point6 = transform.Transform(point3);
                        double x = point4.X;
                        double y = point4.Y;
                        double num7 = Math.Abs((double)(point5.X - point4.X));
                        double num8 = Math.Abs((double)(point6.Y - point4.Y));
                        double num9 = base.ActualHeight * num8;
                        double num10 = base.ActualWidth * num7;
                        if ((num9 != 0.0) && (num10 != 0.0))
                        {
                            num3 *= num7;
                            num4 *= num8;
                            double maxDropDownHeight = this.MaxDropDownHeight;
                            if (double.IsInfinity(maxDropDownHeight) || double.IsNaN(maxDropDownHeight))
                            {
                                maxDropDownHeight = ((actualHeight - num9) * 3.0) / 5.0;
                            }
                            num3 = Math.Min(num3, actualWidth);
                            num4 = Math.Min(num4, maxDropDownHeight);
                            num3 = Math.Max(num10, num3);
                            double num12 = 0.0;
                            if (base.FlowDirection == FlowDirection.LeftToRight)
                            {
                                if (actualWidth < (x + num3))
                                {
                                    num12 = actualWidth - (num3 + x);
                                }
                            }
                            else if (0.0 > (x - num3))
                            {
                                num12 = x - num3;
                            }
                            bool flag = true;
                            double num13 = y + num9;
                            if (actualHeight < (num13 + num4))
                            {
                                flag = false;
                                num13 = y - num4;
                                if (num13 < 0.0)
                                {
                                    if (y < ((actualHeight - num9) / 2.0))
                                    {
                                        flag = true;
                                        num13 = y + num9;
                                    }
                                    else
                                    {
                                        flag = false;
                                        num13 = y - num4;
                                    }
                                }
                            }
                            if (num4 != 0.0)
                            {
                                if (flag)
                                {
                                    maxDropDownHeight = Math.Min(actualHeight - num13, maxDropDownHeight);
                                }
                                else
                                {
                                    maxDropDownHeight = Math.Min(y, maxDropDownHeight);
                                }
                            }
                            this.ElementPopup.HorizontalOffset = 0.0;
                            this.ElementPopup.VerticalOffset = 0.0;
                            this.ElementOutsidePopup.Width = actualWidth / num7;
                            this.ElementOutsidePopup.Height = actualHeight / num8;
                            Matrix identity = Matrix.Identity;
                            identity.OffsetX -= point4.X / num7;
                            identity.OffsetY -= point4.Y / num8;
                            MatrixTransform transform2 = new MatrixTransform
                            {
                                Matrix = identity
                            };
                            this.ElementOutsidePopup.RenderTransform = transform2;
                            double num14 = num10 / num7;
                            this.ElementPopupChild.MinWidth = num14;
                            this.ElementPopupChild.MaxWidth = Math.Max(num14, actualWidth / num7);
                            this.ElementPopupChild.MinHeight = num9 / num8;
                            this.ElementPopupChild.MaxHeight = Math.Max((double)0.0, (double)(maxDropDownHeight / num8));
                            this.ElementPopupChild.HorizontalAlignment = HorizontalAlignment.Left;
                            this.ElementPopupChild.VerticalAlignment = VerticalAlignment.Top;
                            Canvas.SetLeft(this.ElementPopupChild, num12 / num7);
                            Canvas.SetTop(this.ElementPopupChild, (num13 - y) / num8);
                        }
                    }
                }
            }
        }
        private void OnIsDropDownOpenChanged(bool isDropDownOpen)
        {
            //base.ItemContainerGenerator.StopAnimations();
            if (isDropDownOpen)
            {
                if (this.ElementPopup != null)
                {
                    this.ElementPopup.IsOpen = true;
                }
                if (this.ElementDropDownToggle != null)
                {
                    this.ElementDropDownToggle.IsChecked = true;
                }
                this.OnDropDownOpened(EventArgs.Empty);
            }
            else
            {
                if (this.ElementDropDownToggle != null)
                {
                    this.ElementDropDownToggle.IsChecked = false;
                }
                if (this.ElementPopup != null)
                {
                    this.ElementPopup.IsOpen = false;
                }
                this.OnDropDownClosed(EventArgs.Empty);
            }

            this.ChangeVisualState();
        }
        protected virtual void OnDropDownOpened(EventArgs e)
        {
            if (this.DropDownOpened != null)
            {
                this.DropDownOpened(this, e);
            }
        }
        protected virtual void OnDropDownClosed(EventArgs e)
        {
            if (this.DropDownClosed != null)
            {
                this.DropDownClosed(this, e);
            }
        }
        private void SetContentPresenter()
        {
            if (this.ElementContentPresenter != null)
            {
                this.ElementContentPresenter.Content = null;
            }

            string valuePath = SelectedValuePath;
            string displayPath = DisplayMemberPath;
            string valueTemp = string.Empty;
            string displayTemp = string.Empty;

            foreach (var item in ElementItemsPresenter.SelectedItems)
            {
                if (!string.IsNullOrEmpty(valuePath))
                {
                    Binding binding = new Binding(valuePath) { Source = item };
                    ContentControl temp = new ContentControl();
                    temp.SetBinding(ContentControl.ContentProperty, binding);
                    valueTemp = string.Format("{0}{1}{2}", valueTemp, SeparatorChar, temp.Content);

                    temp.ClearValue(ContentControl.ContentProperty);
                }
                else
                {
                    valueTemp = string.Format("{0}{1}{2}", valueTemp, SeparatorChar, item);
                }
                if (!string.IsNullOrEmpty(displayPath))
                {
                    Binding binding = new Binding(displayPath) { Source = item };
                    ContentControl temp = new ContentControl();
                    temp.SetBinding(ContentControl.ContentProperty, binding);
                    displayTemp = string.Format("{0}{1}{2}", displayTemp, SeparatorChar, temp.Content);
                    temp.ClearValue(ContentControl.ContentProperty);
                }
                else
                {
                    displayTemp = string.Format("{0}{1}{2}", displayTemp, SeparatorChar, item);
                }
            }
            SelectedValue = valueTemp.Length > 0 ? valueTemp.Remove(0, 1) : valueTemp;
            this.ElementContentPresenter.Content = displayTemp.Length > 0 ? displayTemp.Remove(0, 1) : displayTemp;
        }
        private void ElementItemsPresenter_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.AddedItems.Count > 0 || e.RemovedItems.Count > 0)
                SetContentPresenter();
            if (SelectionChanged != null)
            {
                SelectionChanged(this, e);
            }
        }
        private void ElementDropDownToggle_Click(object sender, RoutedEventArgs e)
        {
            if (base.IsEnabled)
            {
                base.Focus();
                bool? isChecked = this.ElementDropDownToggle.IsChecked;
                this.IsDropDownOpen = isChecked.HasValue ? isChecked.GetValueOrDefault() : false;
            }
        }
        private void ElementOutsidePopup_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.IsDropDownOpen = false;
        }
        private void ElementPopupChild_MouseEnter(object sender, MouseEventArgs e)
        {
            this._isMouseOverPopup = true;
            this.ChangeVisualState();
        }
        private void ElementPopupChild_MouseLeave(object sender, MouseEventArgs e)
        {
            this._isMouseOverPopup = false;
            this.ChangeVisualState();
        }
        private void ElementPopupChild_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            this.ArrangePopup();
        }

        #region override
        protected override void OnMouseEnter(MouseEventArgs e)
        {
            base.OnMouseEnter(e);
            this._isMouseOverMain = true;
            this.ChangeVisualState();
        }
        protected override void OnMouseLeave(MouseEventArgs e)
        {
            base.OnMouseLeave(e);
            this._isMouseOverMain = false;
            this.ChangeVisualState();
        }
        protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
        {
            base.OnMouseLeftButtonDown(e);
            if (!e.Handled)
            {
                e.Handled = true;
                base.Focus();
                this.IsDropDownOpen = true;
            }
        }
        protected override void OnItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            base.OnItemsChanged(e);
            OnSelectedValueChanged(this.SelectedValue);
        }
        #endregion

        internal void ChangeVisualState()
        {
            this.ChangeVisualState(true);
        }
        private void ChangeVisualState(bool useTransitions)
        {
            if (!base.IsEnabled)
            {
                VisualStateManager.GoToState(this, "Disabled", useTransitions);
            }
            else if (this.IsMouseOver)
            {
                VisualStateManager.GoToState(this, "MouseOver", useTransitions);
            }
            else
            {
                VisualStateManager.GoToState(this, "Normal", useTransitions);
            }
            if (!Selector.GetIsSelectionActive(this))
            {
                VisualStateManager.GoToState(this, "Unfocused", useTransitions);
            }
            else if (this.IsDropDownOpen)
            {
                VisualStateManager.GoToState(this, "FocusedDropDown", useTransitions);
            }
            else
            {
                VisualStateManager.GoToState(this, "Focused", useTransitions);
            }
        }
        internal bool IsMouseOver
        {
            get
            {
                if (!this._isMouseOverMain)
                {
                    return this._isMouseOverPopup;
                }
                return true;
            }
        }
    }
}

CheckedComboBox.xaml

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sys="clr-namespace:System;assembly=mscorlib"
                    xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
                    xmlns:sl="clr-namespace:SL.UI.Form">
    <Style x:Key="checkboxforlistboxitem"
           TargetType="CheckBox">
        <Setter Property="Background"
                Value="#FF448DCA" />
        <Setter Property="Foreground"
                Value="#FF000000" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="VerticalContentAlignment"
                Value="Top" />
        <Setter Property="Padding"
                Value="4,1,0,0" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1"
                                     StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9"
                                  Offset="0" />
                    <GradientStop Color="#FF8399A9"
                                  Offset="0.375" />
                    <GradientStop Color="#FF718597"
                                  Offset="0.375" />
                    <GradientStop Color="#FF617584"
                                  Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CheckBox">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="16" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>
                        <vsm:VisualStateManager.VisualStateGroups教程>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal" />
                                <vsm:VisualState x:Name="MouseOver" />
                                <vsm:VisualState x:Name="Pressed" />
                                <vsm:VisualState x:Name="Disabled" />
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="CheckStates">
                                <vsm:VisualState x:Name="Checked">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="CheckIcon"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Duration="0"
                                                         To="1" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Unchecked" />
                                <vsm:VisualState x:Name="Indeterminate">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="IndeterminateIcon"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Duration="0"
                                                         To="1" />
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="FocusStates">
                                <vsm:VisualState x:Name="Focused" />
                                <vsm:VisualState x:Name="Unfocused" />
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                        <Grid HorizontalAlignment="Left"
                              VerticalAlignment="Top">
                            <Rectangle x:Name="Background"
                                       Width="14"
                                       Height="14"
                                       RadiusX="1"
                                       RadiusY="1"
                                       Stroke="{TemplateBinding BorderBrush}"
                                       StrokeThickness="{TemplateBinding BorderThickness}"
                                       Fill="#FFFFFFFF"
                                       Margin="1" />
                            <Rectangle x:Name="BackgroundOverlay"
                                       Fill="#FFC4DBEE"
                                       Opacity="0"
                                       Width="14"
                                       Height="14"
                                       RadiusX="1"
                                       RadiusY="1"
                                       StrokeThickness="1"
                                       Margin="1"
                                       Stroke="#00000000" />
                            <Rectangle x:Name="BoxMiddleBackground"
                                       Width="10"
                                       Height="10"
                                       RadiusX="1"
                                       RadiusY="1"
                                       Fill="{TemplateBinding Background}"
                                       Stroke="#00000000"
                                       StrokeThickness="1" />
                            <Rectangle x:Name="BoxMiddle"
                                       Width="10"
                                       Height="10"
                                       RadiusX="1"
                                       RadiusY="1"
                                       StrokeThickness="1">
                                <Rectangle.Stroke>
                                    <LinearGradientBrush EndPoint=".5,1"
                                                         StartPoint=".5,0">
                                        <GradientStop Color="#FFFFFFFF"
                                                      Offset="1" />
                                        <GradientStop Color="#FFFFFFFF"
                                                      Offset="0" />
                                        <GradientStop Color="#FFFFFFFF"
                                                      Offset="0.375" />
                                        <GradientStop Color="#FFFFFFFF"
                                                      Offset="0.375" />
                                    </LinearGradientBrush>
                                </Rectangle.Stroke>
                                <Rectangle.Fill>
                                    <LinearGradientBrush StartPoint="0.62,0.15"
                                                         EndPoint="0.64,0.88">
                                        <GradientStop Color="#FFFFFFFF"
                                                      Offset="0.013" />
                                        <GradientStop Color="#F9FFFFFF"
                                                      Offset="0.375" />
                                        <GradientStop Color="#EAFFFFFF"
                                                      Offset="0.603" />
                                        <GradientStop Color="#D8FFFFFF"
                                                      Offset="1" />
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Rectangle x:Name="BoxMiddleLine"
                                       Width="10"
                                       Height="10"
                                       RadiusX="1"
                                       RadiusY="1"
                                       Stroke="{TemplateBinding BorderBrush}"
                                       StrokeThickness="1"
                                       Opacity=".2" />
                            <Path x:Name="CheckIcon"
                                  Margin="1,1,0,1.5"
                                  Fill="#FF333333"
                                  Stretch="Fill"
                                  Opacity="0"
                                  Width="10.5"
                                  Height="10"
                                  Data="M102.03442,598.79645 L105.22962,597.78918 L106.78825,600.42358 C106.78825,600.42358 108.51028,595.74304 110.21724,593.60419 C112.00967,591.35822 114.89314,591.42316 114.89314,591.42316 C114.89314,591.42316 112.67844,593.42645 111.93174,594.44464 C110.7449,596.06293 107.15683,604.13837 107.15683,604.13837 z"
                                  FlowDirection="LeftToRight" />
                            <Rectangle x:Name="IndeterminateIcon"
                                       Height="2"
                                       Fill="#FF333333"
                                       Opacity="0"
                                       Width="6" />
                            <Rectangle x:Name="ContentFocusVisualElement"
                                       RadiusX="2"
                                       RadiusY="2"
                                       Stroke="#FF6DBDD1"
                                       StrokeThickness="1"
                                       Opacity="0"
                                       IsHitTestVisible="false"
                                       Width="16"
                                       Height="16" />
                        </Grid>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style x:Key="CheckedListBoxItemStyle"
           TargetType="ListBoxItem">
        <Setter Property="Padding"
                Value="3" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="VerticalContentAlignment"
                Value="Top" />
        <Setter Property="Background"
                Value="Transparent" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="TabNavigation"
                Value="Local" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Grid Background="{TemplateBinding Background}">
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal" />
                                <vsm:VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="MouseOverColor"
                                                         Storyboard.TargetProperty="Opacity"
                                                         Duration="0"
                                                         To=".8" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="contentPresenter"
                                                         Storyboard.TargetProperty="Opacity"
                                                         Duration="0"
                                                         To=".55" />
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="SelectionStates">
                                <vsm:VisualState x:Name="Unselected" />
                                <vsm:VisualState x:Name="Selected" />
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="FocusStates">
                                <!--<vsm:VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement"
                                                                       Storyboard.TargetProperty="Visibility"
                                                                       Duration="0">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>-->
                                <vsm:VisualState x:Name="Unfocused" />
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                        <Rectangle x:Name="MouseOverColor"
                                   Opacity="0"
                                   Fill="#FF9C9C9C"
                                   IsHitTestVisible="False"
                                   RadiusX="1"
                                   RadiusY="1" />
                        <Rectangle x:Name="SelectedColor"
                                   Opacity="0"
                                   Fill="#FFBADDE9"
                                   IsHitTestVisible="False"
                                   RadiusX="1"
                                   RadiusY="1" />
                        <StackPanel Orientation="Horizontal">
                            <CheckBox IsChecked="{TemplateBinding IsSelected}"
                                      Style="{StaticResource checkboxforlistboxitem}"
                                      IsEnabled="False"
                                      x:Name="ck"
                                      VerticalAlignment="Center" />
                            <ContentPresenter x:Name="contentPresenter"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              Margin="{TemplateBinding Padding}" />
                        </StackPanel>
                        <Rectangle x:Name="FocusVisualElement"
                                   Stroke="#FF6DBDD1"
                                   StrokeThickness="1"
                                   Visibility="Collapsed"
                                   RadiusX="1"
                                   RadiusY="1" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <Style TargetType="sl:CheckedComboBox">
        <Setter Property="Padding"
                Value="6,2,25,2" />
        <Setter Property="Background"
                Value="#FF1F3B53" />
        <Setter Property="HorizontalContentAlignment"
                Value="Left" />
        <Setter Property="BorderThickness"
                Value="1" />
        <Setter Property="TabNavigation"
                Value="Once" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility"
                Value="Auto" />
        <Setter Property="BorderBrush">
            <Setter.Value>
                <LinearGradientBrush EndPoint="0.5,1"
                                     StartPoint="0.5,0">
                    <GradientStop Color="#FFA3AEB9"
                                  Offset="0" />
                    <GradientStop Color="#FF8399A9"
                                  Offset="0.375" />
                    <GradientStop Color="#FF718597"
                                  Offset="0.375" />
                    <GradientStop Color="#FF617584"
                                  Offset="1" />
                </LinearGradientBrush>
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="sl:CheckedComboBox">
                    <Grid>
                        <Grid.Resources>
                            <Style x:Name="comboToggleStyle"
                                   TargetType="ToggleButton">
                                <Setter Property="Foreground"
                                        Value="#FF333333" />
                                <Setter Property="Background"
                                        Value="#FF1F3B53" />
                                <Setter Property="BorderBrush">
                                    <Setter.Value>
                                        <LinearGradientBrush EndPoint="0.5,1"
                                                             StartPoint="0.5,0">
                                            <GradientStop Color="#FFA3AEB9"
                                                          Offset="0" />
                                            <GradientStop Color="#FF8399A9"
                                                          Offset="0.375" />
                                            <GradientStop Color="#FF718597"
                                                          Offset="0.375" />
                                            <GradientStop Color="#FF617584"
                                                          Offset="1" />
                                        </LinearGradientBrush>
                                    </Setter.Value>
                                </Setter>
                                <vsm:Setter Property="BorderThickness"
                                            Value="1" />
                                <Setter Property="Padding"
                                        Value="3" />
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ToggleButton">
                                            <Grid>
                                                <vsm:VisualStateManager.VisualStateGroups>
                                                    <vsm:VisualStateGroup x:Name="CommonStates">
                                                        <vsm:VisualState x:Name="Normal" />
                                                        <vsm:VisualState x:Name="MouseOver">
                                                            <Storyboard>
                                                                <DoubleAnimation Duration="0"
                                                                                 Storyboard.TargetName="BackgroundOverlay"
                                                                                 Storyboard.TargetProperty="Opacity"
                                                                                 To="1" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)"
                                                                                To="#7FFFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
                                                                                To="#CCFFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                                                To="#F2FFFFFF" />
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Pressed">
                                                            <Storyboard>
                                                                <DoubleAnimation Duration="0"
                                                                                 Storyboard.TargetName="BackgroundOverlay2"
                                                                                 Storyboard.TargetProperty="Opacity"
                                                                                 To="1" />
                                                                <DoubleAnimation Duration="0"
                                                                                 Storyboard.TargetName="Highlight"
                                                                                 Storyboard.TargetProperty="(UIElement.Opacity)"
                                                                                 To="1" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                                                To="#E5FFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
                                                                                To="#BCFFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)"
                                                                                To="#6BFFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
                                                                                To="#F2FFFFFF" />
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Disabled" />
                                                    </vsm:VisualStateGroup>
                                                    <vsm:VisualStateGroup x:Name="CheckStates">
                                                        <vsm:VisualState x:Name="Checked">
                                                            <Storyboard>
                                                                <DoubleAnimation Duration="0"
                                                                                 Storyboard.TargetName="BackgroundOverlay3"
                                                                                 Storyboard.TargetProperty="(UIElement.Opacity)"
                                                                                 To="1" />
                                                                <DoubleAnimation Duration="0"
                                                                                 Storyboard.TargetName="Highlight"
                                                                                 Storyboard.TargetProperty="(UIElement.Opacity)"
                                                                                 To="1" />
                                                                <DoubleAnimation Duration="0"
                                                                                 Storyboard.TargetName="BackgroundGradient2"
                                                                                 Storyboard.TargetProperty="(UIElement.Opacity)"
                                                                                 To="1" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient2"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[1].(GradientStop.Color)"
                                                                                To="#E5FFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient2"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[2].(GradientStop.Color)"
                                                                                To="#BCFFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient2"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[3].(GradientStop.Color)"
                                                                                To="#6BFFFFFF" />
                                                                <ColorAnimation Duration="0"
                                                                                Storyboard.TargetName="BackgroundGradient2"
                                                                                Storyboard.TargetProperty="(Shape.Fill).(GradientBrush.GradientStops)[0].(GradientStop.Color)"
                                                                                To="#F2FFFFFF" />
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Unchecked" />
                                                    </vsm:VisualStateGroup>
                                                    <vsm:VisualStateGroup x:Name="FocusStates">
                                                        <vsm:VisualState x:Name="Focused">
                                                            <Storyboard>
                                                                <ObjectAnimationUsingKeyFrames Storyboard.TargetName="FocusVisualElement"
                                                                                               Storyboard.TargetProperty="Visibility"
                                                                                               Duration="0">
                                                                    <DiscreteObjectKeyFrame KeyTime="0">
                                                                        <DiscreteObjectKeyFrame.Value>
                                                                            <Visibility>Visible</Visibility>
                                                                        </DiscreteObjectKeyFrame.Value>
                                                                    </DiscreteObjectKeyFrame>
                                                                </ObjectAnimationUsingKeyFrames>
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Unfocused" />
                                                    </vsm:VisualStateGroup>
                                                </vsm:VisualStateManager.VisualStateGroups>
                                                <Rectangle x:Name="Background"
                                                           RadiusX="3"
                                                           RadiusY="3"
                                                           Fill="{TemplateBinding Background}"
                                                           StrokeThickness="{TemplateBinding BorderThickness}"
                                                           Stroke="{TemplateBinding BorderBrush}" />
                                                <Rectangle x:Name="BackgroundOverlay"
                                                           Opacity="0"
                                                           RadiusX="3"
                                                           RadiusY="3"
                                                           Fill="#FF448DCA"
                                                           StrokeThickness="{TemplateBinding BorderThickness}"
                                                           Stroke="#00000000" />
                                                <Rectangle x:Name="BackgroundOverlay2"
                                                           Opacity="0"
                                                           RadiusX="3"
                                                           RadiusY="3"
                                                           Fill="#FF448DCA"
                                                           StrokeThickness="{TemplateBinding BorderThickness}"
                                                           Stroke="#00000000" />
                                                <Rectangle x:Name="BackgroundGradient"
                                                           RadiusX="2"
                                                           RadiusY="2"
                                                           StrokeThickness="1"
                                                           Margin="{TemplateBinding BorderThickness}"
                                                           Stroke="#FFFFFFFF">
                                                    <Rectangle.Fill>
                                                        <LinearGradientBrush StartPoint=".7,0"
                                                                             EndPoint=".7,1">
                                                            <GradientStop Color="#FFFFFFFF"
                                                                          Offset="0" />
                                                            <GradientStop Color="#F9FFFFFF"
                                                                          Offset="0.375" />
                                                            <GradientStop Color="#E5FFFFFF"
                                                                          Offset="0.625" />
                                                            <GradientStop Color="#C6FFFFFF"
                                                                          Offset="1" />
                                                        </LinearGradientBrush>
                                                    </Rectangle.Fill>
                                                </Rectangle>
                                                <Rectangle Opacity="0"
                                                           x:Name="BackgroundOverlay3"
                                                           RadiusX="3"
                                                           RadiusY="3"
                                                           Fill="#FF448DCA"
                                                           StrokeThickness="{TemplateBinding BorderThickness}"
                                                           Stroke="#00000000" />
                                                <Rectangle Opacity="0"
                                                           x:Name="BackgroundGradient2"
                                                           RadiusX="2"
                                                           RadiusY="2"
                                                           StrokeThickness="1"
                                                           Margin="{TemplateBinding BorderThickness}"
                                                           Stroke="#FFFFFFFF">
                                                    <Rectangle.Fill>
                                                        <LinearGradientBrush StartPoint=".7,0"
                                                                             EndPoint=".7,1">
                                                            <GradientStop Color="#FFFFFFFF"
                                                                          Offset="0" />
                                                            <GradientStop Color="#F9FFFFFF"
                                                                          Offset="0.375" />
                                                            <GradientStop Color="#E5FFFFFF"
                                                                          Offset="0.625" />
                                                            <GradientStop Color="#C6FFFFFF"
                                                                          Offset="1" />
                                                        </LinearGradientBrush>
                                                    </Rectangle.Fill>
                                                </Rectangle>
                                                <Rectangle x:Name="Highlight"
                                                           RadiusX="2"
                                                           RadiusY="2"
                                                           Opacity="0"
                                                           IsHitTestVisible="false"
                                                           Stroke="#FF6DBDD1"
                                                           StrokeThickness="1"
                                                           Margin="{TemplateBinding BorderThickness}" />
                                                <ContentPresenter x:Name="contentPresenter"
                                                                  Content="{TemplateBinding Content}"
                                                                  ContentTemplate="{TemplateBinding ContentTemplate}"
                                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                                  Margin="{TemplateBinding Padding}" />
                                                <Rectangle x:Name="FocusVisualElement"
                                                           RadiusX="3.5"
                                                           Margin="1"
                                                           RadiusY="3.5"
                                                           Stroke="#FF6DBDD1"
                                                           StrokeThickness="1"
                                                           Visibility="Collapsed"
                                                           IsHitTestVisible="false" />
                                            </Grid>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Grid.Resources>
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal" />
                                <vsm:VisualState x:Name="MouseOver" />
                                <vsm:VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <DoubleAnimation Duration="00:00:00"
                                                         Storyboard.TargetName="DisabledVisualElement"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         To=".55" />
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="FocusStates">
                                <vsm:VisualState x:Name="Focused">
                                    <Storyboard>
                                        <DoubleAnimation Duration="00:00:00"
                                                         Storyboard.TargetName="FocusVisualElement"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         To="1" />
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Unfocused" />
                                <vsm:VisualState x:Name="FocusedDropDown">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Duration="00:00:00"
                                                                       Storyboard.TargetName="PopupBorder"
                                                                       Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="ValidationStates">
                                <vsm:VisualState x:Name="Valid" />
                                <vsm:VisualState x:Name="InvalidUnfocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="InvalidFocused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ValidationErrorElement"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip"
                                                                       Storyboard.TargetProperty="IsOpen">
                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <sys:Boolean>True</sys:Boolean>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                        <Border x:Name="ContentPresenterBorder">
                            <Grid>
                                <ToggleButton x:Name="DropDownToggle"
                                              Style="{StaticResource comboToggleStyle}"
                                              HorizontalAlignment="Stretch"
                                              VerticalAlignment="Stretch"
                                              Margin="0"
                                              HorizontalContentAlignment="Right"
                                              Background="{TemplateBinding Background}"
                                              BorderThickness="{TemplateBinding BorderThickness}"
                                              BorderBrush="{TemplateBinding BorderBrush}">
                                    <Path x:Name="BtnArrow"
                                          Height="4"
                                          Width="8"
                                          Stretch="Uniform"
                                          Data="F1 M 301.14,-189.041L 311.57,-189.041L 306.355,-182.942L 301.14,-189.041 Z "
                                          Margin="0,0,6,0"
                                          HorizontalAlignment="Right">
                                        <Path.Fill>
                                            <SolidColorBrush x:Name="BtnArrowColor"
                                                             Color="#FF333333" />
                                        </Path.Fill>
                                    </Path>
                                </ToggleButton>
                                <ContentPresenter x:Name="ContentPresenter"
                                                  Margin="{TemplateBinding Padding}"
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <TextBlock Text=" " />
                                </ContentPresenter>
                            </Grid>
                        </Border>
                        <Rectangle x:Name="DisabledVisualElement"
                                   RadiusX="3"
                                   RadiusY="3"
                                   Fill="White"
                                   Opacity="0"
                                   IsHitTestVisible="false" />
                        <Rectangle x:Name="FocusVisualElement"
                                   RadiusX="2"
                                   RadiusY="2"
                                   Margin="1"
                                   Stroke="#FF6DBDD1"
                                   StrokeThickness="1"
                                   Opacity="0"
                                   IsHitTestVisible="false" />
                        <Border x:Name="ValidationErrorElement"
                                BorderThickness="1"
                                CornerRadius="1"
                                BorderBrush="#FFDB000C"
                                Visibility="Collapsed">
                            <ToolTipService.ToolTip>
                                <ToolTip x:Name="validationTooltip"
                                         Placement="Right"
                                         PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                         DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                                    <ToolTip.Triggers>
                                        <EventTrigger RoutedEvent="Canvas.Loaded">
                                            <EventTrigger.Actions>
                                                <BeginStoryboard>
                                                    <Storyboard>
                                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="validationTooltip"
                                                                                       Storyboard.TargetProperty="IsHitTestVisible">
                                                            <DiscreteObjectKeyFrame KeyTime="0">
                                                                <DiscreteObjectKeyFrame.Value>
                                                                    <sys:Boolean>true</sys:Boolean>
                                                                </DiscreteObjectKeyFrame.Value>
                                                            </DiscreteObjectKeyFrame>
                                                        </ObjectAnimationUsingKeyFrames>
                                                    </Storyboard>
                                                </BeginStoryboard>
                                            </EventTrigger.Actions>
                                        </EventTrigger>
                                    </ToolTip.Triggers>
                                    <ToolTip.Template>
                                        <ControlTemplate>
                                            <Grid x:Name="Root"
                                                  Margin="5,0"
                                                  RenderTransformOrigin="0,0"
                                                  Opacity="0">
                                                <Grid.RenderTransform>
                                                    <TranslateTransform x:Name="xform"
                                                                        X="-25" />
                                                </Grid.RenderTransform>
                                                <vsm:VisualStateManager.VisualStateGroups>
                                                    <vsm:VisualStateGroup Name="OpenStates">
                                                        <vsm:VisualStateGroup.Transitions>
                                                            <vsm:VisualTransition GeneratedDuration="0" />
                                                            <vsm:VisualTransition To="Open"
                                                                                  GeneratedDuration="0:0:0.2">
                                                                <Storyboard>
                                                                    <DoubleAnimation Storyboard.TargetName="xform"
                                                                                     Storyboard.TargetProperty="X"
                                                                                     To="0"
                                                                                     Duration="0:0:0.2">
                                                                        <DoubleAnimation.EasingFunction>
                                                                            <BackEase Amplitude=".3"
                                                                                      EasingMode="EaseOut" />
                                                                        </DoubleAnimation.EasingFunction>
                                                                    </DoubleAnimation>
                                                                    <DoubleAnimation Storyboard.TargetName="Root"
                                                                                     Storyboard.TargetProperty="Opacity"
                                                                                     To="1"
                                                                                     Duration="0:0:0.2" />
                                                                </Storyboard>
                                                            </vsm:VisualTransition>
                                                        </vsm:VisualStateGroup.Transitions>
                                                        <vsm:VisualState x:Name="Closed">
                                                            <Storyboard>
                                                                <DoubleAnimation Storyboard.TargetName="Root"
                                                                                 Storyboard.TargetProperty="Opacity"
                                                                                 To="0"
                                                                                 Duration="0" />
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                        <vsm:VisualState x:Name="Open">
                                                            <Storyboard>
                                                                <DoubleAnimation Storyboard.TargetName="xform"
                                                                                 Storyboard.TargetProperty="X"
                                                                                 To="0"
                                                                                 Duration="0" />
                                                                <DoubleAnimation Storyboard.TargetName="Root"
                                                                                 Storyboard.TargetProperty="Opacity"
                                                                                 To="1"
                                                                                 Duration="0" />
                                                            </Storyboard>
                                                        </vsm:VisualState>
                                                    </vsm:VisualStateGroup>
                                                </vsm:VisualStateManager.VisualStateGroups>
                                                <Border Margin="4,4,-4,-4"
                                                        Background="#052A2E31"
                                                        CornerRadius="5" />
                                                <Border Margin="3,3,-3,-3"
                                                        Background="#152A2E31"
                                                        CornerRadius="4" />
                                                <Border Margin="2,2,-2,-2"
                                                        Background="#252A2E31"
                                                        CornerRadius="3" />
                                                <Border Margin="1,1,-1,-1"
                                                        Background="#352A2E31"
                                                        CornerRadius="2" />

                                                <Border Background="#FFDC000C"
                                                        CornerRadius="2" />
                                                <Border CornerRadius="2">
                                                    <TextBlock UseLayoutRounding="false"
                                                               Foreground="White"
                                                               Margin="8,4,8,4"
                                                               MaxWidth="250"
                                                               TextWrapping="Wrap"
                                                               Text="{Binding (Validation.Errors)[0].ErrorContent}" />
                                                </Border>
                                            </Grid>
                                        </ControlTemplate>

                                    </ToolTip.Template>
                                </ToolTip>
                            </ToolTipService.ToolTip>
                            <Grid Width="12"
                                  Height="12"
                                  HorizontalAlignment="Right"
                                  Margin="1,-4,-4,0"
                                  VerticalAlignment="Top"
                                  Background="Transparent">
                                <Path Margin="1,3,0,0"
                                      Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z"
                                      Fill="#FFDC000C" />
                                <Path Margin="1,3,0,0"
                                      Data="M 0,0 L2,0 L 8,6 L8,8"
                                      Fill="#ffffff" />
                            </Grid>
                        </Border>
                        <Popup x:Name="Popup">
                            <Border x:Name="PopupBorder"
                                    HorizontalAlignment="Stretch"
                                    Height="Auto"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    CornerRadius="1">
                                <Border.Background>
                                    <LinearGradientBrush EndPoint="0.5,1"
                                                         StartPoint="0.5,0">
                                        <GradientStop Color="#FFFFFFFF"
                                                      Offset="0" />
                                        <GradientStop Color="#FFFEFEFE"
                                                      Offset="1" />
                                    </LinearGradientBrush>
                                </Border.Background>
                                <ListBox x:Name="ItemsPresenter"
                                         BorderThickness="0"
                                         ItemsSource="{TemplateBinding ItemsSource}"
                                         ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                         ScrollViewer.VerticalScrollBarVisibility="Auto"
                                         ItemContainerStyle="{StaticResource CheckedListBoxItemStyle}"
                                         SelectionMode="{TemplateBinding SelectionMode}"
                                         Padding="0"
                                         DisplayMemberPath="{TemplateBinding DisplayMemberPath}">
                                </ListBox>
                            </Border>
                        </Popup>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

实例源码下载地址

http://down.zzzyk.com/2011/SL.Controls.Demo.rar

补充:asp.net教程,.Net开发 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,