在Windows Phone 8.1 DatePicker中,无法将类型'%0'的实例添加到类型'%1'的集合中 [英] Cannot add instance of type '%0' to a collection of type '%1' error in windows phone 8.1 DatePicker
问题描述
运行程序后,我收到此错误:
类型为Windows.UI的第一次机会异常。 Xmll.Markup.XamlParseException'发生在App1.exe中WinRT
信息:无法将类型为'%0'的实例添加到
'%1'类型的集合中。 [行:117位置:97]类型
'Windows.UI.Xaml.Markup.XamlParseException'的异常发生在App1.exe中,但
未在用户代码WinRT信息中处理:无法添加
将类型'%1'类型'%1'的类型。 [行:117位置:97]
附加信息:与此错误代码相关联的文本可能
未找到。
我的观点是:
< DatePicker Grid.Row =1Grid.Column = 1
VerticalContentAlignment =Center
HorizontalContentAlignment =Center
HorizontalAlignment =Left
VerticalAlignment =CenterMargin =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日期
{
get {return _dates; }
set
{
_dates = value;
RaisePropertyChanged();
}
}
public ICommand InitializeExpenseListCommand
{
get {return new RelayCommand(InitializeExpenseList()); }
}
public Action InitializeExpenseList()
{
return()=> Debug.WriteLine(_dates);
}
任何人都可以帮我解决这个错误?
我的答案可能有点迟了,但这个错误(仍然)发生(在WinRT 8.1中仍然有消息中的占位符!)如果你尝试的事件添加不存在或者不支持 EventTriggerBehaviour
。支持的事件是:轻敲
, PointerPressed
,加载
, DataContextChanged
,点击
,已检查
,未选中
, SelectionChanged
, TextChanged
,已切换
, NavigationCompleted
请参阅 https://msdn.microsoft.com/en-us/library/windows/apps/dn469361.aspx
Hey I am developing an app in windows phone 8.1 using the MVVM pattern. I want to get the date from the DatePicker on the DateChanged event in the viewModel. After running the program I am getting this error:
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.
My view is:
<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>
And the 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);
}
Can anyone help me in solving this error?
My answer might be a bit late but this error (still) occurs (in WinRT 8.1 still with placeholders in the message!) if the event you try to add either does not exist or is not supported by the EventTriggerBehaviour
. Supported events are: Tapped
, PointerPressed
, Loaded
, DataContextChanged
, Click
, Checked
, Unchecked
, SelectionChanged
, TextChanged
, Toggled
, NavigationCompleted
See https://msdn.microsoft.com/en-us/library/windows/apps/dn469361.aspx
这篇关于在Windows Phone 8.1 DatePicker中,无法将类型'%0'的实例添加到类型'%1'的集合中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!