WPF Linear Fill

Posted by Ben on Stack Overflow See other posts from Stack Overflow or by Ben
Published on 2010-04-28T21:41:14Z Indexed on 2010/04/28 21:47 UTC
Read the original article Hit count: 324

Filed under:
|
|

Hi,

I have found some example code that creates a gradient fill in a WPF rectangle control:

<Rectangle Height="{Binding ElementName=txtName}" Width="{Binding ElementName=txtName}">
                            <Rectangle.Fill>
                                <LinearGradientBrush>
                                    <GradientStop Color="Silver" Offset="0.0" />
                                    <GradientStop Color="Black" Offset="0.5" />
                                    <GradientStop Color="white" Offset="1.0" />
                                </LinearGradientBrush>
                            </Rectangle.Fill>
                        </Rectangle> 

I have some written some code that displays a collection of ListBox's that contain details from MyObject:

<UserControl.Resources>
        <DataTemplate x:Key="CustomerTemplate">
            <Border BorderThickness="2" BorderBrush="Silver" CornerRadius="5" Padding="1" Height="50">
                <Grid x:Name="thisGrid">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <StackPanel Orientation="Horizontal" >
                                <Image Source="C:\MyImage.jpg" Height="50" Width="100" ></Image>
                    </StackPanel>
                    <Border Grid.Column="1" Margin="0" Padding="0">
                            <StackPanel Orientation="Vertical">
                            <TextBlock Name="txtName" Text="{Binding Name}" Background="Silver" Foreground="Black" FontSize="16" FontWeight="Bold" Height="25"/>
                        </StackPanel>
                    </Border>

                </Grid>
            </Border>
        </DataTemplate>
</UserControl.Resources>
    <ListBox ItemsSource="{Binding}" ItemTemplate="{StaticResource CustomerTemplate}" 
                 Name="grdList" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >

    </ListBox>

I would like to apply the same stlye of fill that i get with the first example, in each of my ListBox's. I can't quite figure out how to do this. Can anyone help?

Thanks

© Stack Overflow or respective owner

Related posts about wpf

Related posts about c#