Fill xaml rectangle multiples solidcolorbrush

前端 未结 2 453
旧巷少年郎
旧巷少年郎 2021-01-14 12:02

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

\"enter

I don\'t want

相关标签:
2条回答
  • 2021-01-14 12:32

    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>
    
    0 讨论(0)
  • 2021-01-14 12:55

    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) } };
    
    0 讨论(0)
提交回复
热议问题