view MetroWpf/MetroWpf.Xaml/Styles/Controls.WatermarkTextBox.xaml @ 105:1c9fc59af186

Removing old files
author stevenhollidge <stevenhollidge@hotmail.com>
date Sun, 06 May 2012 12:32:35 +0100
parents 8049f7c58c2b
children
line wrap: on
line source

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:Microsoft.Windows.Controls"
                    xmlns:System="clr-namespace:System;assembly=mscorlib">

  <LinearGradientBrush x:Key="TextBoxBorder" EndPoint="0,20" MappingMode="Absolute" StartPoint="0,0">
    <GradientStop Color="#ABADB3" Offset="0.05"/>
    <GradientStop Color="#E2E3EA" Offset="0.07"/>
    <GradientStop Color="#E3E9EF" Offset="1"/>
  </LinearGradientBrush>

  <LinearGradientBrush x:Key="TextBox_MouseOver" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#5794BF" Offset="0.05"/>
    <GradientStop Color="#B7D5EA" Offset="0.07"/>
    <GradientStop Color="#C7E2F1" Offset="1"/>
  </LinearGradientBrush>

  <LinearGradientBrush x:Key="TextBox_Focused" EndPoint="0,1" StartPoint="0,0">
    <GradientStop Color="#3D7BAD" Offset="0.05"/>
    <GradientStop Color="#A4C9E3" Offset="0.07"/>
    <GradientStop Color="#B7D9ED" Offset="1"/>
  </LinearGradientBrush>

  <SolidColorBrush x:Key="TextBox_DisabledBorder" Color="#ADB2B5" />
  <SolidColorBrush x:Key="TextBox_DisabledBackground" Color="#F4F4F4" />

  <DataTemplate x:Key="DefaultWatermarkTemplate">
    <ContentControl Content="{Binding}" Foreground="Gray" Focusable="False" />
  </DataTemplate>

  <Style TargetType="{x:Type local:WatermarkTextBox}">
    <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
    <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
    <Setter Property="BorderThickness" Value="1" />
    <Setter Property="Height" Value="26" />
    <Setter Property="MinHeight" Value="26" />
    <Setter Property="Background" Value="{DynamicResource ControlBackgroundBrush}" />
    <Setter Property="Foreground" Value="{DynamicResource TextBrush}" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <Setter Property="Padding" Value="0" />
    <Setter Property="BorderBrush" Value="{DynamicResource TextBoxBorderBrush}" />
    <Setter Property="AllowDrop" Value="true"/>
    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
    <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst"/>
    <Setter Property="Stylus.IsFlicksEnabled" Value="False"/>
    <Setter Property="WatermarkTemplate" Value="{StaticResource DefaultWatermarkTemplate}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate TargetType="{x:Type local:WatermarkTextBox}">
          <Grid>
            <VisualStateManager.VisualStateGroups>
              <VisualStateGroup x:Name="CommonStates">
                <VisualState x:Name="Normal" />
                <VisualState x:Name="MouseOver">
                  <Storyboard>
                    <DoubleAnimation Duration="0"
                                    To="1"
                                    Storyboard.TargetProperty="(UIElement.Opacity)"
                                    Storyboard.TargetName="FocusRectangle" />
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Disabled">
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                                       Storyboard.TargetName="DisabledVisualElement">
                      <SplineDoubleKeyFrame KeyTime="0"
                                                                  Value="1" />
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="ReadOnly">
                  <Storyboard>
                    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity"
                                                                       Storyboard.TargetName="ReadOnlyVisualElement">
                      <SplineDoubleKeyFrame KeyTime="0"
                                                                  Value="1" />
                    </DoubleAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
              <VisualStateGroup x:Name="FocusStates">
                <VisualState x:Name="Focused">
                  <Storyboard>
                    <DoubleAnimation Duration="0"
                                                         To="1"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Storyboard.TargetName="FocusRectangle" />
                    <DoubleAnimation Duration="0"
                                                         To="1"
                                                         Storyboard.TargetProperty="(UIElement.Opacity)"
                                                         Storyboard.TargetName="FocusInnerRectangle" />
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="Unfocused">
                  <Storyboard />
                </VisualState>
              </VisualStateGroup>
              <VisualStateGroup x:Name="ValidationStates">
                <VisualState x:Name="Valid" />
                <VisualState x:Name="InvalidUnfocused">
                  <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                                       Storyboard.TargetName="ValidationErrorElement">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
                <VisualState x:Name="InvalidFocused">
                  <Storyboard>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Visibility"
                                                                       Storyboard.TargetName="ValidationErrorElement">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <Visibility>Visible</Visibility>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsOpen"
                                                                       Storyboard.TargetName="validationTooltip">
                      <DiscreteObjectKeyFrame KeyTime="0">
                        <DiscreteObjectKeyFrame.Value>
                          <System:Boolean>True</System:Boolean>
                        </DiscreteObjectKeyFrame.Value>
                      </DiscreteObjectKeyFrame>
                    </ObjectAnimationUsingKeyFrames>
                  </Storyboard>
                </VisualState>
              </VisualStateGroup>
            </VisualStateManager.VisualStateGroups>
            <Rectangle x:Name="Base"
                        Stroke="{TemplateBinding BorderBrush}"
                        StrokeThickness="{TemplateBinding BorderThickness}"
                        Opacity="1"
                        Fill="{TemplateBinding Background}" />
            <Rectangle x:Name="FocusRectangle"
                      StrokeThickness="{TemplateBinding BorderThickness}"
                      Opacity="0"
                      Stroke="{DynamicResource TextBoxMouseOverBorderBrush}" />
            <Rectangle x:Name="FocusInnerRectangle"
                      StrokeThickness="{TemplateBinding BorderThickness}"
                      Opacity="0"
                      Margin="1"
                      Stroke="{DynamicResource TextBoxMouseOverInnerBorderBrush}" />
            <Grid Margin="0,1,0,0" >
              <Border x:Name="ReadOnlyVisualElement"
                      Background="{x:Null}"
                      Opacity="0"/>
              <Grid Margin="8,0,0,0">
                <ScrollViewer x:Name="PART_ContentHost" 
                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                <ContentPresenter x:Name="PART_WatermarkHost" 
                                  Content="{TemplateBinding Watermark}"
                                  ContentTemplate="{TemplateBinding WatermarkTemplate}"
                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"                                       
                                  IsHitTestVisible="False"
                                  Margin="{TemplateBinding Padding}"
                                  Visibility="Collapsed"/>

              </Grid>
            </Grid>
            <Rectangle x:Name="DisabledVisualElement"
                                   Stroke="{DynamicResource ControlsDisabledBrush}"
                                   StrokeThickness="{TemplateBinding BorderThickness}"
                                   Fill="{DynamicResource ControlsDisabledBrush}"
                                   IsHitTestVisible="False"
                                   Opacity="0" />
            <Border x:Name="ValidationErrorElement"
                                BorderBrush="{DynamicResource ControlsValidationBrush}"
                                BorderThickness="1"
                                Visibility="Collapsed">
              <ToolTipService.ToolTip>
                <ToolTip x:Name="validationTooltip"
                                         DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                         Placement="Right"
                                         PlacementTarget="{Binding RelativeSource={RelativeSource TemplatedParent}}"
                                         Template="{DynamicResource ValidationToolTipTemplate}">
                  <ToolTip.Triggers>
                    <EventTrigger RoutedEvent="Canvas.Loaded">
                      <BeginStoryboard>
                        <Storyboard>
                          <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="IsHitTestVisible"
                                                                                   Storyboard.TargetName="validationTooltip">
                            <DiscreteObjectKeyFrame KeyTime="0">
                              <DiscreteObjectKeyFrame.Value>
                                <System:Boolean>true</System:Boolean>
                              </DiscreteObjectKeyFrame.Value>
                            </DiscreteObjectKeyFrame>
                          </ObjectAnimationUsingKeyFrames>
                        </Storyboard>
                      </BeginStoryboard>
                    </EventTrigger>
                  </ToolTip.Triggers>
                </ToolTip>
              </ToolTipService.ToolTip>
              <Grid Background="Transparent"
                                  HorizontalAlignment="Right"
                                  Height="12"
                                  Margin="1,-4,-4,0"
                                  VerticalAlignment="Top"
                                  Width="12">
                <Path Data="M 1,0 L6,0 A 2,2 90 0 1 8,2 L8,7 z"
                                      Fill="{DynamicResource ValidationBrush5}"
                                      Margin="1,3,0,0" />
                <Path Data="M 0,0 L2,0 L 8,6 L8,8"
                                      Fill="{DynamicResource WhiteColorBrush}"
                                      Margin="1,3,0,0" />
              </Grid>
            </Border>
          </Grid>
          <ControlTemplate.Triggers>
            <MultiTrigger>
              <MultiTrigger.Conditions>
                <Condition Property="IsFocused" Value="False"></Condition>
                <Condition Property="Text" Value=""></Condition>
              </MultiTrigger.Conditions>
              <MultiTrigger.Setters>
                <Setter Property="Visibility" TargetName="PART_WatermarkHost" Value="Visible"></Setter>
              </MultiTrigger.Setters>
            </MultiTrigger>
          </ControlTemplate.Triggers>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

</ResourceDictionary>