c# - 如何创建和初始化自定义 Xamarin Forms 控件

标签 c# xaml xamarin.ios xamarin.forms

我想在 Xamarin Forms 中创建一个简单的自定义控件 (ContentView),它基本上是一个包含可变数量图像的 StackLayout。这个想法是可以在 XAML 页面中像这样实例化它:

 <views:MyControl Pages="4" CurrentPage="2"/>

然后,在后面的代码中,我可以为每个页面添加一个图像,并根据 CurrentPage 值设置源。但是,我无法弄清楚的是属性值何时可用于影响布局。在构造函数中,Pages 和 CurrentPage 为空。

在使用自定义 ContentView 时,我应该在哪里以及如何考虑属性值?

最佳答案

听起来您可能正在尝试创建类似于 CarouselPage 的东西,它允许您以类似于画廊的方式在内容页面之间左右滑动。

https://developer.xamarin.com/guides/xamarin-forms/user-interface/navigation/carousel-page/

好消息是,在 Forms 2.2(目前处于预览阶段,可以通过 nuget 获得)中,CarouselPage 类正在被 CarouselView 取代,这很棒,因为您现在可以将它嵌入到页面中,而不是它本身就是主页容器。

我建议您查看:

https://www.nuget.org/packages/Xamarin.Forms/2.2.0.23-pre4

看看它是否符合您的要求。快速谷歌一下,发现已经有一些教程在各种博客上涌现出来。

关于c# - 如何创建和初始化自定义 Xamarin Forms 控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36801964/

相关文章:

c# - Elasticsearch 嵌套 : Fetching random documents

c# - Silverlight:在 DataGridRowGroupHeader 事件中获取 RowGroupHeader 值

ios - Xamarin iOS : Check if Google fit app is installed on the device

ios - uitableview 返回 2 cellIdentifier

c# - 从 WebMethod 返回要在 jQuery 中使用的多个值

c# - 使用 NEST 进行 Elasticsearch - 异步操作

c# - 无法理解如何在单元测试中使用 Mock

.net - Mono 是否支持 XAML?

c# - 在 XAML 中处理 Button 的 Click 事件?

uiwebview - 在仅限 iPhone 的应用程序中播放 YouTube 视频 - 失去控制