简体   繁体   中英

Creating Xamarin Forms control from existing controls

In Xamarin Forms there is a TimePicker control. I can instantiate the control from my xaml code and bind the Time property to a property on my view model.

I would like to create a similar control for selecting days of the week ("Monday", "Tuesday", etc). Let's call it DaysOfWeekPicker . DaysOfWeekPicker should allow the user to select zero, one or multiple (up to 7) days. This is different to the standard Picker which only allows exactly one item to be selected.

I've found tutorials which explain how to create custom controls with native renderers defined for each platform. However, as a first pass, I would be happy to implement DaysOfWeekPicker using just the other controls that already exist in Xamarin Forms such as buttons and labels. Is there a way I can do this without creating new renderers for each platform?

You can achieve this by adding a ContentView to your project

Xamarin添加ContentView

Your ContentView can have a XAML file which you can use to define its looks or you can do that in the code behind

Take a look at Bindable Properties (especially about property change events) and Behaviors and investigate how they work. You will likely need to write some code to define how your control works, moves, responds, validates etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM