C# ';未找到“的属性、BindableProperty或事件”;“选定日期”';和';“财产”;“选定日期”;在类型“中找不到”;“日期选择器”';
我正在将一个项目从标准的Xamarin.Forms移动应用程序转换为使用MVVM格式。在转换为MVVM之前,该应用程序的所有功能都按预期工作。在为我的一个视图设置我的ViewModel并将C# ';未找到“的属性、BindableProperty或事件”;“选定日期”';和';“财产”;“选定日期”;在类型“中找不到”;“日期选择器”';,c#,xamarin.forms,mvvm,data-binding,datepicker,C#,Xamarin.forms,Mvvm,Data Binding,Datepicker,我正在将一个项目从标准的Xamarin.Forms移动应用程序转换为使用MVVM格式。在转换为MVVM之前,该应用程序的所有功能都按预期工作。在为我的一个视图设置我的ViewModel并将SelectedDate属性添加到我的DatePicker之后,我开始收到一个错误:在类型“DatePicker”中找不到属性“SelectedDate”。 在启动“全部清除”和“全部重建”之后,我还开始收到另一个错误:没有为“SelectedDate”找到属性、BindableProperty或事件,或者值和
SelectedDate
属性添加到我的DatePicker
之后,我开始收到一个错误:在类型“DatePicker”中找不到属性“SelectedDate”。
在启动“全部清除”和“全部重建”之后,我还开始收到另一个错误:没有为“SelectedDate”找到属性、BindableProperty或事件,或者值和属性之间的类型不匹配。
我的XAML文件的适用部分:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="StarTracker.AddAdventurePage"
BackgroundColor="{StaticResource lightBlue}">
<StackLayout HorizontalOptions="CenterAndExpand"
VerticalOptions="CenterAndExpand">
<CollectionView x:Name="NewAdventure"
HorizontalOptions="CenterAndExpand"
SelectionMode="None">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Text="Date Played: "
FontFamily="Axion"
TextColor="{StaticResource red}"
Grid.Row="0"
Grid.Column="0"/>
<DatePicker x:Name="PlayedDatePicker"
FontFamily="Axion"
Grid.Row="0"
Grid.Column="1"
SelectedDate="{Binding Date}"
TextColor="{StaticResource darkBlue}"
MinimumDate="08/17/2017"
MaximumDate="{x:Static sys:DateTime.Today}">
<DatePicker.Format>MM/dd/yyyy</DatePicker.Format>
</DatePicker>
查找后,我将ViewModel更改为从BindableObject
派生,并将INotifyPropertyChanged
,然后将日期获取/设置更改为:
public static readonly BindableProperty DateProperty = BindableProperty.Create(
nameof(Date),
typeof(DateTime),
typeof(DatePicker));
public DateTime Date
{
get { return (DateTime)GetValue(DateProperty); }
set
{
SetValue(DateProperty, value);
OnPropertyChanged("Date");
}
}
我仍然有IntelliSense告诉我,SelectedDate
不是DatePicker
中的一个属性,根据我的判断,这是不准确的。my other选择器中的SelectedItem
绑定可以正常工作
我缺少什么可以让我使用DatePicker
中的SelectedDate
属性并通过我的数据绑定保存信息?Xamarin表单没有SelectedDate
属性,它有Date属性
Date类型为DateTime,所选日期,默认为值
日期时间,今天
您在帖子中链接到的文档是针对System.Windows.Controls.DatePicker。。。你说得对。你难道不知道切换到Date
并进行重建修复了错误吗。谢谢
public static readonly BindableProperty DateProperty = BindableProperty.Create(
nameof(Date),
typeof(DateTime),
typeof(DatePicker));
public DateTime Date
{
get { return (DateTime)GetValue(DateProperty); }
set
{
SetValue(DateProperty, value);
OnPropertyChanged("Date");
}
}