Lu1zZz
Lu1zZz

Reputation: 57

Fill xaml rectangle multiples solidcolorbrush

This type of fill in rectangle in xaml is it possible?

enter image description here

I don't want to use gradient to fill the rectangle, as in the image per section using solid colorbrush different.

Thanks

Upvotes: 3

Views: 1806

Answers (2)

bdimag
bdimag

Reputation: 963

Re: your comment -- is the concern simply that it's an N amount of rectangles? If it's not a constraint that it all be one rectangle, you could do something like this:

    <ListView ItemsSource="{Binding ColorsTiles}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <ListView ItemsSource="{Binding}">
                    <ListView.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ListView.ItemsPanel>
                    <ListView.ItemTemplate>
                        <DataTemplate>
                            <Rectangle Fill="{Binding}" Width="100" Height="100" />
                        </DataTemplate>
                    </ListView.ItemTemplate>
                </ListView>
            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>

and

ColorsTiles = new ObservableCollection<ObservableCollection<SolidColorBrush>>() {
        new ObservableCollection<SolidColorBrush>(){ new SolidColorBrush(Colors.LightGreen), new SolidColorBrush(Colors.LightBlue), new SolidColorBrush(Colors.Blue) },
        new ObservableCollection<SolidColorBrush>(){ new SolidColorBrush(Colors.LightSeaGreen), new SolidColorBrush(Colors.Pink), new SolidColorBrush(Colors.Red) } };

Upvotes: 1

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33391

Try this:

<Rectangle Width="300" Height="100" Stroke="black" StrokeThickness="3">
  <Rectangle.Fill>
    <LinearGradientBrush StartPoint="0 0" EndPoint="1 0">
      <GradientStop Color="red" Offset="0"/>
      <GradientStop Color="red" Offset=".33"/>
      <GradientStop Color="black" Offset=".33"/>
      <GradientStop Color="black" Offset=".34"/>
      <GradientStop Color="green" Offset=".34"/>
      <GradientStop Color="green" Offset=".66"/>
      <GradientStop Color="black" Offset=".66"/>
      <GradientStop Color="black" Offset=".67"/>
      <GradientStop Color="cyan" Offset=".67"/>
    </LinearGradientBrush>
  </Rectangle.Fill>
</Rectangle>

Upvotes: 5

Related Questions