Есть ли способ отображать элементы из списка один за другим и прокручивать их? - PullRequest
0 голосов
/ 11 июля 2020

В настоящее время в моем разделе календаря я получаю события из календаря Google, и элементы отображаются следующим образом. The listview have height auto, and show all elements

what I want is show this elements, one by one and adjust the height so its fits the element content which you are seeing and then scroll through the list to see the others elements.

And everytime you scroll down the listview is going to readjust the height to fit the new element.

Something like this

Showing just first element

Then you scroll

Showing just the second element with a new height

But i dont know who to do this, if i bind the height to the wrapper of the element in the datatemplate just ignore the bind. And you can scroll through the elements without select them, so i cant modify the template for selected items, or bind with the selected item.

Searching i have found some ways to modify the item height to the parent height, but that's not what i want, is the opposite.

my xaml

                    

Ответы [ 2 ]

0 голосов
/ 13 июля 2020

Я закончил использовать поле со списком вместо списка, потому что я не хочу использовать что-то взломанное, которое может закончиться странными вещами, а flipview не работал должным образом, поэтому на самом деле он лучший.

Так как мне нужно ждать в любом случае, если бы кто-то дал лучшее решение, было бы очень хорошо.

0 голосов
/ 12 июля 2020

Простой шаблон:

     <ListView   SelectedIndex="0">
   <ListView.Template>
    <ControlTemplate TargetType="ListView">
     <Grid>
      <Grid.ColumnDefinitions>
       <ColumnDefinition Width="*" />
       <ColumnDefinition Width="Auto" />
      </Grid.ColumnDefinitions>
      <ContentControl HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                      VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                      ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                      ContentTemplate="{TemplateBinding ItemTemplate}"
                      Content="{TemplateBinding SelectedItem}" />
      <ScrollBar Minimum="0"
                 Value="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=SelectedIndex,Mode=TwoWay}"
                 Maximum="{Binding RelativeSource={RelativeSource Mode=TemplatedParent},Path=Items.Count,Converter={StaticResource ResourceKey=ToRealCount}}"
                 Grid.Column="1"
                 ViewportSize="0.5" />
     </Grid>
    </ControlTemplate>
   </ListView.Template>
   <ListView.Items>
    <Rectangle Fill="Violet"
               Width="100"
               Height="100" />
    <Rectangle Fill="Aqua"
               Width="100"
               Height="100" />
    <Rectangle Fill="Green"
               Width="100"
               Height="100" />
    <Rectangle Fill="Red"
               Width="100"
               Height="100" />
   </ListView.Items>
   <ListBox.ItemsPanel>
    <ItemsPanelTemplate>
     <VirtualizingStackPanel />
    </ItemsPanelTemplate>
   </ListBox.ItemsPanel>
  </ListView>

Конвертер:

 public class ToRealCount : IValueConverter
 {
  public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  {
   if (value is int count)
   {
    return count > 0 ? count - 1 : count;
   }
   return 0;
  }

  public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  {
   throw new NotImplementedException();
  }
 }

вы тоже можете рассмотреть этот вариант flipview

...