AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.76k stars 2.23k forks source link

Using C# 8.0 Range operator in Binding #7123

Open workgroupengineering opened 2 years ago

workgroupengineering commented 2 years ago

Allow using sitax like this in Binding

  <!-- Bind AvailableItems from 3° to end -->
  <Listbox Items="{Binding AvailableItems[3..]}">
  </Listbox>

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered There is a problem, the operator ^ already used on https://docs.avaloniaui.net/docs/data-binding/binding-to-tasks-and-observables

Additional context Documentation

grokys commented 2 years ago

Can you give some examples of where this would be useful? I'm struggling to think of a use-case which require displaying a fixed subset of items.

workgroupengineering commented 2 years ago

<Grid>
   <Grid.ColumnDefinitions>
      <ColumnDefinition/>
      <ColumnDefinition/>
      <ColumnDefinition/>
      <ColumnDefinition/>
   <Grid.ColumnDefinitions>
   <Grid.RowDefinitions>
       <RowDefinition Height="Auto" />
       <RowDefinition Height="*" />
   </Grid.RowDefinitions> 
   <TextBlock Text="A"/>
   <TextBlock Text="B" Grid.Column="1"/>
   <TextBlock Text="C" Grid.Column="2"/>
   <TextBlock Text="D" Grid.Column="3"/>  
   <ItemsControl Items="{Binding Scores[0..4]}"
              Grid.Row="1"
              Grid.Column="0"/> 
   <ItemsControl Items="{Binding Scores[5..9]}"
              Grid.Row="1"
              Grid.Column="1"/> 
   <ItemsControl Items="{Binding Scores[10..14]}"
              Grid.Row="1"
              Grid.Column="2"/> 
   <ItemsControl Items="{Binding Scores[15..19]}"
              Grid.Row="1"
              Grid.Column="3"/> 
</Grid>