Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
i have one rectangle and suppose width is 150.i want fill rectangle in 3 color.means i want show 1-50 in blue then 51-100 is red then 101-150 green help me?
Posted

1 solution

A WPF rectangle can only have one colour which is defined by the Fill property.
You could write a User Control which consists of three rectangles. e.g.

SpecialRectangle.xaml:
XML
<UserControl x:Class="WpfApplication9.SpecialRectangle"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Rectangle Grid.Column="0" Fill="Blue"></Rectangle>
        <Rectangle Grid.Column="1" Fill="Red"></Rectangle>
        <Rectangle Grid.Column="2" Fill="Green"></Rectangle>
    </Grid>
</UserControl>

You could then use this on any window like this:

MainWindow.xaml:
C#
<Window x:Class="WpfApplication9.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:WpfApplication9"
        Title="MainWindow" Height="400" Width="525">
    <Grid>            
        <local:SpecialRectangle></local:SpecialRectangle>
    </Grid>
</Window>
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900