Permalink
Browse files

fix disabled ComboBox style

  • Loading branch information...
1 parent 98ca697 commit 97fa00f0f7588f6f6b63ec33bd9144d431d827d1 @punker76 punker76 committed Feb 23, 2015
Showing with 253 additions and 14 deletions.
  1. +253 −14 MahApps.Metro/Styles/Controls.ComboBox.xaml
@@ -2,8 +2,259 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Controls="clr-namespace:MahApps.Metro.Controls">
+ <ResourceDictionary.MergedDictionaries>
+ <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TextBox.xaml" />
+ </ResourceDictionary.MergedDictionaries>
+
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
+ <Style x:Key="EditableTextBoxStyle"
+ TargetType="{x:Type TextBox}"
+ BasedOn="{StaticResource MetroTextBox}">
+ <Setter Property="MinHeight"
+ Value="26" />
+ <Setter Property="Template">
+ <Setter.Value>
+ <ControlTemplate TargetType="{x:Type TextBox}">
+ <ControlTemplate.Resources>
+ <Storyboard x:Key="enterGotFocus">
+ <DoubleAnimation Duration="0:0:0.2"
+ To=".2"
+ Storyboard.TargetProperty="Opacity"
+ Storyboard.TargetName="Message" />
+ </Storyboard>
+ <Storyboard x:Key="exitGotFocus">
+ <DoubleAnimation Duration="0:0:0.2"
+ Storyboard.TargetProperty="Opacity"
+ Storyboard.TargetName="Message" />
+ </Storyboard>
+
+ <Storyboard x:Key="enterHasText">
+ <DoubleAnimation Duration="0:0:0.2"
+ From=".2"
+ To="0"
+ Storyboard.TargetProperty="Opacity"
+ Storyboard.TargetName="Message" />
+ </Storyboard>
+ <Storyboard x:Key="exitHasText">
+ <DoubleAnimation Duration="0:0:0.2"
+ Storyboard.TargetProperty="Opacity"
+ Storyboard.TargetName="Message" />
+ </Storyboard>
+ </ControlTemplate.Resources>
+ <Grid>
+ <Border x:Name="Base"
+ SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
+ BorderBrush="{TemplateBinding BorderBrush}"
+ BorderThickness="{TemplateBinding BorderThickness}"
+ Background="{TemplateBinding Background}" />
+ <Grid x:Name="PART_InnerGrid"
+ Margin="2">
+ <Grid.ColumnDefinitions>
+ <ColumnDefinition Width="*" />
+ <ColumnDefinition x:Name="ButtonColumn"
+ Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ButtonWidth), Mode=OneWay}" />
+ </Grid.ColumnDefinitions>
+ <Grid.RowDefinitions>
+ <RowDefinition Height="Auto" />
+ <RowDefinition x:Name="ButtonRow"
+ Height="*" />
+ </Grid.RowDefinitions>
+
+ <Border x:Name="ReadOnlyVisualElement"
+ Grid.Row="1"
+ Grid.ColumnSpan="2"
+ Background="{x:Null}"
+ Opacity="0" />
+ <ScrollViewer x:Name="PART_ContentHost"
+ Grid.Column="0"
+ Grid.Row="1"
+ BorderThickness="0"
+ IsTabStop="False"
+ Margin="2"
+ VerticalAlignment="Stretch"
+ Background="{x:Null}" />
+ <TextBlock x:Name="Message"
+ Grid.Column="0"
+ Grid.Row="1"
+ Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
+ Padding="{TemplateBinding Padding}"
+ Visibility="Collapsed"
+ Foreground="{TemplateBinding Foreground}"
+ IsHitTestVisible="False"
+ Opacity="0.6"
+ HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
+ VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
+ Margin="6,2,6,2" />
+ <Grid x:Name="FloatingMessageContainer"
+ Grid.Column="0"
+ Grid.ColumnSpan="2"
+ Height="0"
+ IsHitTestVisible="False"
+ Margin="5,0"
+ Visibility="Visible">
+ <TextBlock x:Name="FloatingMessage"
+ Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
+ FontSize="{DynamicResource FloatingWatermarkFontSize}"
+ Foreground="{TemplateBinding Foreground}"
+ Opacity="0.6"
+ HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
+ VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
+ <TextBlock.RenderTransform>
+ <TranslateTransform />
+ </TextBlock.RenderTransform>
+ </TextBlock>
+ </Grid>
+ <Button x:Name="PART_ClearText"
+ Grid.Column="1"
+ Grid.RowSpan="2"
+ Style="{DynamicResource ChromelessButtonStyle}"
+ FontSize="16"
+ Foreground="{TemplateBinding Foreground}"
+ FontFamily="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonFontFamily), Mode=OneWay}"
+ Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContent), Mode=OneWay}"
+ Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
+ Controls:TextBoxHelper.IsClearTextButtonBehaviorEnabled="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay}"
+ IsTabStop="False" />
+ </Grid>
+ </Grid>
+ <ControlTemplate.Triggers>
+ <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}"
+ Value="">
+ <Setter TargetName="Message"
+ Property="Visibility"
+ Value="Visible" />
+ </DataTrigger>
+
+ <!--Sets the MiniMessage visibility (Watermark must not be "" and FloatWatermark must be true)-->
+ <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.HasText)}"
+ Value="False">
+ <DataTrigger.EnterActions>
+ <BeginStoryboard Storyboard="{StaticResource HideFloatingMessageStoryboard}" />
+ </DataTrigger.EnterActions>
+ <DataTrigger.ExitActions>
+ <BeginStoryboard Storyboard="{StaticResource ShowFloatingMessageStoryboard}" />
+ </DataTrigger.ExitActions>
+ </DataTrigger>
+ <!--To override Watermark == ""-->
+ <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.Watermark)}"
+ Value="">
+ <DataTrigger.EnterActions>
+ <BeginStoryboard Storyboard="{StaticResource HideFloatingMessageStoryboard}" />
+ </DataTrigger.EnterActions>
+ <DataTrigger.ExitActions>
+ <BeginStoryboard Storyboard="{StaticResource ShowFloatingMessageStoryboard}" />
+ </DataTrigger.ExitActions>
+ </DataTrigger>
+ <!--To override TextBoxHelper.UseFloatingWatermark == false-->
+ <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.UseFloatingWatermark)}"
+ Value="False">
+ <DataTrigger.EnterActions>
+ <BeginStoryboard Storyboard="{StaticResource HideFloatingMessageStoryboard}" />
+ </DataTrigger.EnterActions>
+ <DataTrigger.ExitActions>
+ <BeginStoryboard Storyboard="{StaticResource ShowFloatingMessageStoryboard}" />
+ </DataTrigger.ExitActions>
+ </DataTrigger>
+
+ <!-- multiline textbox cannot bind to actual height so take the fallbach button width -->
+ <MultiTrigger>
+ <MultiTrigger.Conditions>
+ <Condition Property="TextWrapping"
+ Value="NoWrap" />
+ <Condition Property="AcceptsReturn"
+ Value="False" />
+ </MultiTrigger.Conditions>
+ <Setter TargetName="ButtonColumn"
+ Property="Width"
+ Value="{Binding ElementName=ButtonRow, Path=ActualHeight, Mode=OneWay}" />
+ </MultiTrigger>
+
+ <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ClearTextButton)}"
+ Value="False">
+ <Setter TargetName="PART_ContentHost"
+ Property="Grid.ColumnSpan"
+ Value="2" />
+ <Setter TargetName="Message"
+ Property="Grid.ColumnSpan"
+ Value="2" />
+ </DataTrigger>
+ <Trigger Property="IsMouseOver"
+ Value="True">
+ <Setter TargetName="Base"
+ Property="BorderBrush"
+ Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.MouseOverBorderBrush)}" />
+ </Trigger>
+ <Trigger Property="IsReadOnly"
+ Value="True">
+ <Setter TargetName="ReadOnlyVisualElement"
+ Property="Opacity"
+ Value="1" />
+ </Trigger>
+ <Trigger Property="IsFocused"
+ Value="True">
+ <Setter TargetName="Base"
+ Property="BorderBrush"
+ Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.FocusBorderBrush)}" />
+ <Setter TargetName="FloatingMessage"
+ Property="Foreground"
+ Value="{DynamicResource AccentColorBrush}" />
+ <Setter TargetName="FloatingMessage"
+ Property="Opacity"
+ Value="1" />
+ </Trigger>
+ <Trigger SourceName="PART_ClearText"
+ Property="IsMouseOver"
+ Value="True">
+ <Setter TargetName="PART_ClearText"
+ Property="Background"
+ Value="{DynamicResource GrayBrush8}" />
+ <Setter TargetName="PART_ClearText"
+ Property="Foreground"
+ Value="{DynamicResource AccentColorBrush}" />
+ </Trigger>
+ <Trigger SourceName="PART_ClearText"
+ Property="IsPressed"
+ Value="True">
+ <Setter TargetName="PART_ClearText"
+ Property="Background"
+ Value="{DynamicResource BlackBrush}" />
+ <Setter TargetName="PART_ClearText"
+ Property="Foreground"
+ Value="{DynamicResource WhiteBrush}" />
+ </Trigger>
+
+ <MultiTrigger>
+ <MultiTrigger.Conditions>
+ <Condition Property="Controls:TextBoxHelper.HasText"
+ Value="False" />
+ <Condition Property="IsFocused"
+ Value="True" />
+ </MultiTrigger.Conditions>
+ <MultiTrigger.EnterActions>
+ <BeginStoryboard Storyboard="{StaticResource enterGotFocus}" />
+ </MultiTrigger.EnterActions>
+ <MultiTrigger.ExitActions>
+ <BeginStoryboard Storyboard="{StaticResource exitGotFocus}" />
+ </MultiTrigger.ExitActions>
+ </MultiTrigger>
+
+ <Trigger Property="Controls:TextBoxHelper.HasText"
+ Value="True">
+ <Trigger.EnterActions>
+ <BeginStoryboard Storyboard="{StaticResource enterHasText}" />
+ </Trigger.EnterActions>
+ <Trigger.ExitActions>
+ <BeginStoryboard Storyboard="{StaticResource exitHasText}" />
+ </Trigger.ExitActions>
+ </Trigger>
+
+ </ControlTemplate.Triggers>
+ </ControlTemplate>
+ </Setter.Value>
+ </Setter>
+ </Style>
+
<Style TargetType="{x:Type ComboBox}"
x:Key="MetroComboBox">
<Setter Property="MinHeight"
@@ -57,14 +308,6 @@
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}" />
- <Border x:Name="DisabledVisualElement"
- SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
- BorderBrush="{DynamicResource ControlsDisabledBrush}"
- BorderThickness="{TemplateBinding BorderThickness}"
- Background="{DynamicResource ControlsDisabledBrush}"
- Opacity="0.6"
- IsHitTestVisible="False"
- Visibility="Collapsed" />
<Grid Margin="1">
<Grid.ColumnDefinitions>
@@ -139,12 +382,6 @@
Property="Background"
Value="{DynamicResource GrayBrush7}" />
</Trigger>
- <Trigger Property="IsEnabled"
- Value="False">
- <Setter TargetName="DisabledVisualElement"
- Property="Visibility"
- Value="Visible" />
- </Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
@@ -198,6 +435,7 @@
Margin="0,0,-2,0"
Background="{TemplateBinding Background}">
<TextBox x:Name="PART_EditableTextBox"
+ Style="{StaticResource EditableTextBoxStyle}"
HorizontalAlignment="Stretch"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
@@ -234,6 +472,7 @@
Background="{x:Null}"
Visibility="Collapsed" />
<Border x:Name="DisabledVisualElement"
+ Grid.ColumnSpan="3"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
BorderBrush="{DynamicResource ControlsDisabledBrush}"
BorderThickness="{TemplateBinding BorderThickness}"

0 comments on commit 97fa00f

Please sign in to comment.