I'm trying to do something so simple but cannot get anywhere with it. I've been trawling the net trying to find a clear example or tit bit of information but every article I find is showing the exact same simple example.
All I want to do is have a background to a list box item that is two tone but without a gradial blend between them. So far I have:
<Setter Property="Background" >
<Setter.Value>
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#ACC6E0" Offset="0"/>
<GradientStop Color="#DCE7F5" Offset="1"/>
</LinearGradientBrush>
</Setter.Value>
</Setter>
I've tried plenty of different things but all I end up with is a variant of a gradual gradient not a two tone equal split.
Many Thanks
Paul
Just add two stops at the same offset:
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#ACC6E0" Offset="0"/>
<GradientStop Color="#ACC6E0" Offset="0.5"/>
<GradientStop Color="#DCE7F5" Offset="0.5"/>
<GradientStop Color="#DCE7F5" Offset="1"/>
</LinearGradientBrush>
In fact you can drop the end points:
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#ACC6E0" Offset="0.5"/>
<GradientStop Color="#DCE7F5" Offset="0.5"/>
</LinearGradientBrush>
You need to add extra GradientStops:
<LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
<GradientStop Color="#ACC6E0" Offset="0"/>
<GradientStop Color="#ACC6E0" Offset="0.5"/>
<GradientStop Color="#DCE7F5" Offset="0.5"/>
<GradientStop Color="#DCE7F5" Offset="1"/>
</LinearGradientBrush>
Related
I currently have a gradient set up in XAML as follows:
<Canvas>
<Canvas.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Red" Offset="0.5"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
</Canvas>
Result:
However, this is not what I want to achieve. What I want is to have one gradient transition to a solid colour. Below is what I am trying to achieve:
As one can see from the above image, there is a white-red gradient at the top, and that transitions smoothly to black as it goes down. I have yet to find a way to do this, and this is where I need help. Is there a way to do this? If there is, what is the best way to achieve this (that you know of)?
You may overlay a second element with a perpendicular LinearGradientBrush that changes opacity:
<Grid>
<Canvas>
<Canvas.Background>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
</Canvas>
<Canvas>
<Canvas.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
</Canvas>
</Grid>
I currently have a gradient set up in XAML as follows:
<Canvas>
<Canvas.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Red" Offset="0.5"/>
<GradientStop Color="White" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
</Canvas>
Result:
However, this is not what I want to achieve. What I want is to have one gradient transition to a solid colour. Below is what I am trying to achieve:
As one can see from the above image, there is a white-red gradient at the top, and that transitions smoothly to black as it goes down. I have yet to find a way to do this, and this is where I need help. Is there a way to do this? If there is, what is the best way to achieve this (that you know of)?
You may overlay a second element with a perpendicular LinearGradientBrush that changes opacity:
<Grid>
<Canvas>
<Canvas.Background>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="1,0.5">
<GradientStop Color="White" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
</Canvas>
<Canvas>
<Canvas.Background>
<LinearGradientBrush StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#00000000" Offset="0"/>
<GradientStop Color="Black" Offset="1"/>
</LinearGradientBrush>
</Canvas.Background>
</Canvas>
</Grid>
To have brush:
I'm currently write this code:
<LinearGradientBrush EndPoint="1,0">
<GradientStop Offset="{Binding Path=offset1}" Color="{Binding Path=g1}"/>
<GradientStop Offset="{Binding Path=offset1}" Color="{Binding Path=g2}"/> <!-- -->
<GradientStop Offset="{Binding Path=offset2}" Color="{Binding Path=g2}"/> <!-- -->
<GradientStop Offset="{Binding Path=offset2}" Color="{Binding Path=g3}"/>
</LinearGradientBrush>
That's what a kind of cheat! I'm wondering is there is a better way to do this?
I am trying to style my own datagrid and here's what I am doing:
<DataGrid x:Name="datagrid_1" Margin="554,92,52,373" ItemsSource="{Binding}" >
<DataGridRow>
<DataGridRow.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF878787" Offset="1"/>
</LinearGradientBrush>
</DataGridRow.Background>
</DataGridRow>
<DataGridColumnHeader>
<DataGridColumnHeader.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</DataGridColumnHeader.Background>
</DataGridColumnHeader>
<DataGridCell>
<DataGridCell.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="#FF878787" Offset="1"/>
</LinearGradientBrush>
</DataGridCell.Background>
<DataGridCell.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</DataGridCell.BorderBrush>
</DataGridCell>
<DataGridRowHeader>
<DataGridRowHeader.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="0"/>
<GradientStop Color="Red" Offset="1"/>
</LinearGradientBrush>
</DataGridRowHeader.Background>
</DataGridRowHeader>
</DataGrid>
The thing is it just doesn't change the default style, and I really don't know what is the problem, I think I'm doing everything right. Any help out here pls? Thanks in advance.
Try something like this to set style to your DATAGRID..
This is just an example so that you can start and get your own DatagridStyle.
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Background" Value="Transparent" />
</Trigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
Here is my XAML
<Border Grid.Column="1" BorderBrush="Black" Margin="5">
<Border.Background>
<LinearGradientBrush EndPoint=".5,1" StartPoint=".5,0">
<GradientStop Color="#FFFFFFFF" Offset="0"/>
<GradientStop Color="#FFf3f3f3" Offset="0.48"/>
<GradientStop Color="#FFededed" Offset="0.51"/>
<GradientStop Color="#FFFFFFFF" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
</Border>
I can see border at design time but it doesn't show at run-time. Why?
Whats wrong with it?!
You need to set the BorderThickness.