在Windows Phone 8.1 DatePicker中,无法将类型’%0’的实例添加到类型’%1’的集合中
作者:互联网
嘿,我正在使用MVVM模式在Windows Phone 8.1中开发一个应用程序.我想从viewModel的DateChanged事件上的DatePicker获取日期.
运行程序后,我得到此错误:
A first chance exception of type ‘Windows.UI.Xaml.Markup.XamlParseException’ occurred in App1.exe WinRT
information: Cannot add instance of type ‘%0’ to a collection of type
‘%1’. [Line: 117 Position: 97] An exception of type
‘Windows.UI.Xaml.Markup.XamlParseException’ occurred in App1.exe but
was not handled in user code WinRT information: Cannot add instance of
type ‘%0’ to a collection of type ‘%1’. [Line: 117 Position: 97]
Additional information: The text associated with this error code could
not be found.
我的看法是:
<DatePicker Grid.Row="1" Grid.Column="1"
VerticalContentAlignment="Center"
HorizontalContentAlignment="Center"
HorizontalAlignment="Left"
VerticalAlignment="Center" Margin="26,-0.333,0,0.5"
Date="{Binding Dates, Mode=TwoWay}">
<i:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="DateChanged">
<core:InvokeCommandAction Command="{Binding InitializeExpenseListCommand}"/>
</core:EventTriggerBehavior>
</i:Interaction.Behaviors>
</DatePicker>
和viewModel:
public MainViewModel()
{
_dates = new DateTimeOffset(DateTime.Now);
}
private DateTimeOffset _dates;
public DateTimeOffset Dates
{
get { return _dates; }
set
{
_dates = value;
RaisePropertyChanged();
}
}
public ICommand InitializeExpenseListCommand
{
get { return new RelayCommand(InitializeExpenseList()); }
}
public Action InitializeExpenseList()
{
return () => Debug.WriteLine(_dates);
}
谁能帮助我解决这个错误?
解决方法:
如果您尝试添加的事件不存在或EventTriggerBehaviour不支持,则我的回答可能有点晚,但是会出现此错误(仍然)(在WinRT 8.1中消息中仍带有占位符!).支持的事件包括:轻击,PointerPressed,已加载,DataContextChanged,Click,选中,未选中,SelectionChanged,TextChanged,Toggled,NavigationCompleted
查看https://msdn.microsoft.com/en-us/library/windows/apps/dn469361.aspx
标签:datepicker,windows-phone-8-1,xaml,c,mvvm 来源: https://codeday.me/bug/20191120/2046226.html