如何在Xamarin.forms中旋转视图
我们有没有办法创建旋转视图而不是旋转页面,这样页面的一部分就可以向左或向右滑动。我还想在Xamarin表单中创建此控件,而不是特定于平台如何在Xamarin.forms中旋转视图,xamarin,carousel,xamarin.forms,Xamarin,Carousel,Xamarin.forms,我们有没有办法创建旋转视图而不是旋转页面,这样页面的一部分就可以向左或向右滑动。我还想在Xamarin表单中创建此控件,而不是特定于平台 如果我们需要在xamarin.android或xamarin.iOS中创建此自定义控件,那么在无法满足此简单要求的情况下使用xamarin.forms的真正好处是什么。我刚刚实现了类似的功能。为了创建旋转木马视图,我刚刚创建了一个水平Stacklayout,包装在水平滚动视图中 在我的特定示例中,我需要创建一个图像库。我使用Xamarin.Labs项目中的相机
如果我们需要在xamarin.android或xamarin.iOS中创建此自定义控件,那么在无法满足此简单要求的情况下使用xamarin.forms的真正好处是什么。我刚刚实现了类似的功能。为了创建旋转木马视图,我刚刚创建了一个水平Stacklayout,包装在水平滚动视图中 在我的特定示例中,我需要创建一个图像库。我使用Xamarin.Labs项目中的相机控件从相机卷或相机本身获取图像。然后,我将其作为子项添加到Stacklayout中
希望这能有所帮助。github上有一个记录良好的CarouseView项目: 和
自
Xamarin.Forms V2.2.0-pre1起
CarouselView
现已添加到Xamarin.Forms中
旋转视图
CarouselView旨在完全取代CarouselPage。旋转木马
将在将来的版本中弃用。CarouselView在以下方面具有优势
多种方式,包括虚拟化和嵌套在
布局
看
不幸的是,到目前为止还没有关于这方面的文档
编辑:
已删除Xamarin.Forms V2.2.0.31的CarouselView
,因为它尚未准备好稳定发布。但从表面上看,它很快就会被合并回来
现在,您可以在这里找到单独的CarouselView
nuget包:
您可以这样使用它:
名称空间:
xmlns:cv="clr-namespace:Xamarin.Forms;assembly=Xamarin.Forms.CarouselView"
然后,我们只需在页面顶部添加旋转视图:
<Grid RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height=".3*"/>
<RowDefinition Height=".7*"/>
</Grid.RowDefinitions>
<cv:CarouselView ItemsSource="{Binding Zoos}" x:Name="CarouselZoos">
<cv:CarouselView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Grid.RowSpan="2" Aspect="AspectFill" Source="{Binding ImageUrl}"/>
<StackLayout Grid.Row="1" BackgroundColor="#80000000" Padding="12">
<Label TextColor="White" Text="{Binding Name}" FontSize="16" HorizontalOptions="Center" VerticalOptions="CenterAndExpand"/>
</StackLayout>
</Grid>
</DataTemplate>
</cv:CarouselView.ItemTemplate>
</cv:CarouselView>
<!--List of Monkeys below-->
</Grid>
更多信息:旋转视图的nuget软件包现在可用(v2.3.0-pre1):
如果您使用Xamarin.Forms V2.2.0-pre1,并且需要为每个页面显示不同的视图,则可以使用如下派生类:
public class CarouselViewMultiPage : CarouselView
{
List<View> _children = new List<View> { };
public List<View> Children {
get { return _children; }
set {
_children = value;
OnPropertyChanged();
}
}
public CarouselViewMultiPage ()
{
this.ItemTemplate = new CarouselTemplateSelector();
this.ItemsSource = Children;
this.SetBinding(CarouselView.ItemsSourceProperty, "Children");
BindingContext = this;
}
}
public class CarouselTemplateSelector : DataTemplateSelector
{
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
DataTemplate dt = new DataTemplate();
View civ = (View)item;
return new DataTemplate(() =>
{
return civ;
});
}
}
Xamarin forms v4.4中引入了CarouselView。你可以看看。除了旋转木马视图
,还添加了指示器视图
,以指示旋转木马中的第n个项目 我们可以使用Xamarin forms 4.3中引入的CarouselView。现在在Xamarin4.6中,我们不必使用Forms.SetFlags(“CollectionView_”)
但是,要在旋转木马页面上使用指示器视图,我们必须设置此选项
Forms.SetFlags(“IndicatorView_实验”);在iOS的appdelegate和android的mainactivity中。您想知道什么还不清楚。你想要水平幻灯片吗?你想要一个带3D动画的旋转木马吗?你只是想知道Xamarin.表格是否适合你的需要吗?看起来旋转视图已经不存在了。发生了什么事?CarouseView在V2.2.0.31
中被删除,因为它还没有准备好发布。但从外观上看,它将被合并回下一个稳定版本这是否意味着使用此软件包不安全?@batmaci Pre-Release意味着使用该软件包,但请注意,它可能会包含bug,对于需要修改的应用程序来说并不理想released@user1您知道如何使用mvvm实现PostionSelected事件吗?会吗在VS 2015附带的Xamarin版本中是否适用于Windows phone、UWP和Windows项目类型?
public App()
{
// The root page of your application
MainPage = new ContentPage {
Content = new CarouselViewMultiPage
{
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand,
Children =
{
new Label() { Text="Page 1"},
new Label() { Text="Page 2"},
new Label() { Text="Page 3"},
}
}
};
}