简体   繁体   中英

Xamarin.Forms - DatePicker duplicating

In my app I have a DatePicker. My xaml code is this:

<StackLayout Orientation="Horizontal">
    <DatePicker x:Name="startDate"
                Date="{Binding CurrentCourse.Start}"
                TextColor="Red"/>
    <DatePicker/>
    <DatePicker x:Name="endDate"
                Date="{Binding CurrentCourse.End}"
                TextColor="Blue"/>
    <DatePicker/>
</StackLayout>

Both controls get rendered properly, but next to each is another DatePicker for some reason. This duplicate DatePicker doesn't share the TextColor property either, so it's extra weird.

Does anyone know what could be happening here? I don't have any code elsewhere that does anything with DatePickers, so it's not happening in another module or something.

The Picture below shows the strange behavior.

奇怪的 DatePicker 重复。

You have 4 complete <DatePicker /> entries in your XML.

It's doing exactly as you tell it.

This first one is complete in itself:

<DatePicker x:Name="startDate"
                Date="{Binding CurrentCourse.Start}"
                TextColor="Red"/>

See the / by the closing angle bracket? That's the end of the element, and it's a valid DatePicker Element.

Then you have a complete new one, with no styling or binding:

<DatePicker/>

That's the one that shows black.

Just delete the two stand-alone entries.

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