嗨,我正在使用MVVM模式在Windows Phone 8.1中开发应用程序。 我想在viewModel中从中获取日期,在上执行操作。 运行程序后,我遇到了以下错误:
在App1.exe WinRT中发生了'Type 'Windows.UI.Xaml.Markup.XamlParseException'的第一次机会异常信息:无法将类型为'%0'的实例添加到类型为'%1'的集合中。[Line: 117 Position: 97]在用户代码中, 发生了类型为'Windows.UI.Xaml.Markup.XamlParseException'的异常信息WinRT信息: 无法将类型为'%0'的实例添加到类型为'%1'的集合中。[Line: 117 Position: 97]附加信息:找不到与此错误代码关联的文本。
我的视图是:
<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);
}
有人能帮我解决这个错误吗?
DateChanged
引起的。我已将其更改为Tapped
,然后它正常工作了。你能告诉我DateChanged
事件有什么问题吗?或者是否有任何类似的事件? - Utsav Dawn