none
Can't set Background -> LinearGradientBrush

    Question

  • <Border CornerRadius="5" Margin="5">
              <Border.Background>
                <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                  <GradientStop Color="#cccccc" Offset="0"></GradientStop>
                  <GradientStop Color="Transparent" Offset="2"></GradientStop>
                </LinearGradientBrush>
              </Border.Background>
              <Border.Style>
                <Style>
                  <Style.Triggers>
                    <Trigger Property="Border.IsMouseOver" Value="True">
                      <Setter Property="Border.Background">
                        <Setter.Value>
                          <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                            <GradientStop Color="#888888" Offset="0"></GradientStop>
                            <GradientStop Color="Transparent" Offset="1"></GradientStop>
                          </LinearGradientBrush>
                        </Setter.Value>
                      </Setter>
                    </Trigger>
                  </Style.Triggers>
                </Style>
              </Border.Style>
    [...]
    </Border>
    
    This code seems to be valid, though the gradient doesn't change. Other setters in the triggergroup work.
    Sunday, April 17, 2011 5:29 PM

Answers

  • You may change your code as below
    <Border>
          
          <Border.Style>
            <Style>
              <Setter Property="Border.Background">
                <Setter.Value>
                  <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                    <GradientStop Color="#cccccc" Offset="0"></GradientStop>
                    <GradientStop Color="Transparent" Offset="2"></GradientStop>
                  </LinearGradientBrush>
                </Setter.Value>
              </Setter>
              <Style.Triggers>
                <Trigger Property="Border.IsMouseOver" Value="True">
                  <Setter Property="Border.Background">
                    <Setter.Value>
                      <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                        <GradientStop Color="#888888" Offset="0"></GradientStop>
                        <GradientStop Color="Transparent" Offset="1"></GradientStop>
                      </LinearGradientBrush>
                    </Setter.Value>
                  </Setter>
                </Trigger>
              </Style.Triggers>
            </Style>
          </Border.Style>
        </Border>

    Ajosh Jose
    • Marked as answer by iAlex59 Monday, April 18, 2011 1:23 AM
    Monday, April 18, 2011 1:16 AM

All replies

  • Hi!

    to make it work, you need to set the initial value of the background property into the style property as follows:

    	<Border CornerRadius="5" Margin="5" Grid.Row="1" >
    		<Border.Style>
          <Style>
          	<Setter Property="Border.Background">
          		<Setter.Value>
          			<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
    			       <GradientStop Color="#cccccc" Offset="0"></GradientStop>
    			       <GradientStop Color="Transparent" Offset="2"></GradientStop>
    			      </LinearGradientBrush>    		
    					</Setter.Value>    	
    				</Setter>
    				<Style.Triggers>
            	<Trigger Property="Border.IsMouseOver" Value="True">
            		<Setter Property="Border.Background">
              		<Setter.Value>
               			<LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                			<GradientStop Color="#888888" Offset="0"></GradientStop>
                			<GradientStop Color="Transparent" Offset="1"></GradientStop>
               			</LinearGradientBrush>
              		</Setter.Value>
             		</Setter>
            	</Trigger>
           	</Style.Triggers>
    			</Style>
    		</Border.Style>
    	</Border>

    Hope this helps!

     


    Sergio Garrido. Mi Blog
    Sunday, April 17, 2011 6:24 PM
  • Doesn't solve the problem, thanks anyway.
    Sunday, April 17, 2011 11:49 PM
  • You may change your code as below
    <Border>
          
          <Border.Style>
            <Style>
              <Setter Property="Border.Background">
                <Setter.Value>
                  <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                    <GradientStop Color="#cccccc" Offset="0"></GradientStop>
                    <GradientStop Color="Transparent" Offset="2"></GradientStop>
                  </LinearGradientBrush>
                </Setter.Value>
              </Setter>
              <Style.Triggers>
                <Trigger Property="Border.IsMouseOver" Value="True">
                  <Setter Property="Border.Background">
                    <Setter.Value>
                      <LinearGradientBrush EndPoint="1,0" StartPoint="0,0">
                        <GradientStop Color="#888888" Offset="0"></GradientStop>
                        <GradientStop Color="Transparent" Offset="1"></GradientStop>
                      </LinearGradientBrush>
                    </Setter.Value>
                  </Setter>
                </Trigger>
              </Style.Triggers>
            </Style>
          </Border.Style>
        </Border>

    Ajosh Jose
    • Marked as answer by iAlex59 Monday, April 18, 2011 1:23 AM
    Monday, April 18, 2011 1:16 AM
  • Hi Jose Atlanta,

    Thank you for your friendly help.

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, April 19, 2011 5:01 AM
    Moderator