我想在Xamarin表單中實現水平滾動列表視圖,並且我嘗試了幾個庫,但找不到好的解決方案。這是可能的Xamrin形式(沒有呈現),並有工作庫我可以使用?水平列表視圖Xamarin表格
回答
嘗試https://www.nuget.org/packages/HorizontalListView1.1/
使用範例:(XAML)
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="test.ListPage" xmlns:Controls="clr-namespace:test;assembly=test">
<Controls:HorizontalListView ItemsSource="{Binding Categories}" ListOrientation="Horizontal">
<Controls:HorizontalListView.ItemTemplate>
<DataTemplate>
<Label Text="{Binding Name}" Grid.Row="0" YAlign="Center" />
</DataTemplate>
</Controls:HorizontalListView.ItemTemplate>
</Controls:myControl>
謝謝。我會試試這個。 – droidNDK
中序,讓你必須創建一個自定義的滾動型水平滾動列表視圖的注意和XAML
使用這種自定義控件public class ImageGallery:ScrollView { readonly StackLayout _imageStack;
public ImageGallery()
{
this.Orientation = ScrollOrientation.Horizontal;
_imageStack = new StackLayout
{
Orientation = StackOrientation.Horizontal
};
this.Content = _imageStack;
}
public IList<View> Children
{
get
{
return _imageStack.Children;
}
}
public static readonly BindableProperty ItemsSourceProperty =
BindableProperty.Create<ImageGallery, IList>(
view => view.ItemsSource,
default(IList),
BindingMode.TwoWay,
propertyChanging: (bindableObject, oldValue, newValue) => {
((ImageGallery)bindableObject).ItemsSourceChanging();
},
propertyChanged: (bindableObject, oldValue, newValue) => {
((ImageGallery)bindableObject).ItemsSourceChanged(bindableObject, oldValue, newValue);
}
);
public IList ItemsSource
{
get
{
return (IList)GetValue(ItemsSourceProperty);
}
set
{
SetValue(ItemsSourceProperty, value);
}
}
void ItemsSourceChanging()
{
if (ItemsSource == null)
return;
}
void ItemsSourceChanged(BindableObject bindable, IList oldValue, IList newValue)
{
if (ItemsSource == null)
return;
var notifyCollection = newValue as INotifyCollectionChanged;
if (notifyCollection != null)
{
notifyCollection.CollectionChanged += (sender, args) => {
if (args.NewItems != null)
{
foreach (var newItem in args.NewItems)
{
var view = (View)ItemTemplate.CreateContent();
var bindableObject = view as BindableObject;
if (bindableObject != null)
bindableObject.BindingContext = newItem;
_imageStack.Children.Add(view);
}
}
if (args.OldItems != null)
{
// not supported
_imageStack.Children.RemoveAt(args.OldStartingIndex);
}
};
}
}
public DataTemplate ItemTemplate
{
get;
set;
}
public static readonly BindableProperty SelectedItemProperty =
BindableProperty.Create<ImageGallery, object>(
view => view.SelectedItem,
null,
BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) => {
((ImageGallery)bindable).UpdateSelectedIndex();
}
);
public object SelectedItem
{
get
{
return GetValue(SelectedItemProperty);
}
set
{
SetValue(SelectedItemProperty, value);
}
}
void UpdateSelectedIndex()
{
if (SelectedItem == BindingContext)
return;
SelectedIndex = Children
.Select(c => c.BindingContext)
.ToList()
.IndexOf(SelectedItem);
}
public static readonly BindableProperty SelectedIndexProperty =
BindableProperty.Create<ImageGallery, int>(
carousel => carousel.SelectedIndex,
0,
BindingMode.TwoWay,
propertyChanged: (bindable, oldValue, newValue) => {
((ImageGallery)bindable).UpdateSelectedItem();
}
);
public int SelectedIndex
{
get
{
return (int)GetValue(SelectedIndexProperty);
}
set
{
SetValue(SelectedIndexProperty, value);
}
}
void UpdateSelectedItem()
{
SelectedItem = SelectedIndex > -1 ? Children[SelectedIndex].BindingContext : null;
}
}`
現在你可以使用XAML中的自定義滾動型得到一個水平滾動列表
<custom:ImageGallery ItemsSource="{Binding ImageList}" HeightRequest="100"> <custom:ImageGallery.ItemTemplate> <DataTemplate>
< - 通過旋轉的ListView> </DataTemplate> </custom:ImageGallery.ItemTemplate> </custom:ImageGallery>
謝謝。我會試試這個。 – droidNDK
一些創建水平列表視圖 - 佈局和相關的東西,然後旋轉元素。
這是一個破解,你必須確保它不會妨礙你的佈局(不要把它放在網格中)。但它工作正常。
- 1. 降低水平列表視圖的高度 - xamarin表格
- 2. Xamarin格式的列表視圖項水平
- 3. iOS水平列表視圖
- 4. 的水平列表視圖
- 5. 可可單行表格視圖或水平列表視圖
- 6. JavaFX水平圖表列表
- 7. 水平曲線列表視圖
- 8. Xamarin.Forms中的水平列表視圖
- 9. Android的列表視圖水平
- 10. 水平列表視圖自定義列表視圖項不顯示視圖
- 11. Xamarin窗體水平列表視圖顯示來自ObservableCollection的圖像
- 12. Flex水平貼圖列表
- 13. 網格中列表視圖項後的水平線
- 14. Xamarin水平視圖與按鈕
- 15. Xamarin窗體列表視圖
- 16. 水平列表視圖中添加頁腳視圖
- 17. 利用水平滾動視圖和下面的列表視圖
- 18. Android:垂直滾動視圖中的水平列表視圖?
- 19. 網格水平視圖
- 20. 頁面有水平列表視圖,並在屏幕上顯示該列表數據Xamarin表單
- 21. Xamarin表單列表視圖行寬
- 22. Xamarin表單列表視圖綁定
- 23. 水平列的表
- 24. 水平列表框
- 25. PyGTK水平列表
- 26. Flex水平列表
- 27. 表/集合視圖的水平滾動
- 28. android:水平拉伸表面視圖
- 29. 表格內聯和水平與圖像
- 30. 將列表視圖劃分爲列,使用水平滾動(wpf)
也許是CarouselView? –