IntegerUpDown and Disabled Background

May 30, 2012 at 11:26 AM

I want to be able to change the background color of the IntegerUpDown control when disabled.  So far I am quite unsuccessful at this.  What's the best way to do this by it's design?  Or is this an issue with the control?

Jun 4, 2012 at 11:19 AM

Hello?  Do I need post this in the issue tracker?

Coordinator
Jun 4, 2012 at 3:24 PM

Hi,

 

To be able to change the background color of the IntegerUpDown, you will have to alter the ControlTemplate of the WatermarkTextBox control that is within the IntegerUpDown.  Here is an implicit style that will do just what you want.  You will need to change the color of the SolidColorBrush named "TextBox_DisabledBackground" to the one you want.

 

<Style TargetType="xctk:IntegerUpDown"
       BasedOn="{StaticResource {x:Type xctk:IntegerUpDown}}">
   <Style.Resources>
      <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" />

      <Style TargetType="xctk:WatermarkTextBox"
               BasedOn="{StaticResource {x:Type xctk:WatermarkTextBox}}">
         <Setter Property="Template">
            <Setter.Value>
               <ControlTemplate TargetType="xctk:WatermarkTextBox">
                  <Grid>
                     <Border x:Name="Border" 
                              BorderThickness="{TemplateBinding BorderThickness}"
                              BorderBrush="{TemplateBinding BorderBrush}"
                              CornerRadius="1"
                              Background="{TemplateBinding Background}" />
                     <Border x:Name="MouseOverVisual"
                              Opacity="0"
                              BorderThickness="{TemplateBinding BorderThickness}"
                              BorderBrush="{StaticResource TextBox_MouseOver}"
                              CornerRadius="1" />
                     <Border x:Name="FocusVisual"
                              Opacity="0"
                              BorderThickness="{TemplateBinding BorderThickness}"
                              BorderBrush="{StaticResource TextBox_Focused}"
                              CornerRadius="1" />
                     <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>
                  <ControlTemplate.Triggers>
                     <MultiTrigger>
                        <MultiTrigger.Conditions>
                           <Condition Property="IsFocused" Value="False" />
                           <Condition Property="Text" Value="" />
                        </MultiTrigger.Conditions>
                        <MultiTrigger.Setters>
                           <Setter Property="Visibility" TargetName="PART_WatermarkHost" Value="Visible" />
                        </MultiTrigger.Setters>
                     </MultiTrigger>
                     <Trigger Property="IsMouseOver" Value="True">
                        <Setter TargetName="MouseOverVisual" Property="Opacity" Value="1" />
                     </Trigger>
                     <Trigger Property="IsFocused" Value="True">
                        <Setter TargetName="FocusVisual" Property="Opacity" Value="1" />
                     </Trigger>
                     <Trigger Property="IsEnabled" Value="false">
                        <Setter TargetName="Border"  Property="BorderBrush" Value="{StaticResource TextBox_DisabledBorder}" />
                        <Setter TargetName="Border"  Property="Background" Value="{StaticResource TextBox_DisabledBackground}" />
                        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                     </Trigger>
                  </ControlTemplate.Triggers>
               </ControlTemplate>
            </Setter.Value>
         </Setter>
      </Style>
   </Style.Resources>
</Style>