简体   繁体   English

无法在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

Hey I am developing an app in windows phone 8.1 using the MVVM pattern. 嘿我正在使用MVVM模式在windows phone 8.1中开发一个应用程序。 I want to get the date from the DatePicker on the DateChanged event in the viewModel. 我想从viewModel中DateChanged事件DatePicker获取日期。 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'. App1.exe WinRT信息中出现'Windows.UI.Xaml.Markup.XamlParseException'类型的第一次机会异常:无法将类型'%0'的实例添加到类型'%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'. [行:117位置:97] App1.exe中出现“Windows.UI.Xaml.Markup.XamlParseException”类型的异常,但未在用户代码中处理WinRT信息:无法将“%0”类型的实例添加到集合中类型'%1'。 [Line: 117 Position: 97] Additional information: The text associated with this error code could not be found. [行:117位置:97]其他信息:找不到与此错误代码关联的文本。

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: 和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 . 我的回答可能有点迟,但是如果您尝试添加的事件不存在或者不受EventTriggerBehaviour支持,则会出现此错误(仍然)(在WinRT 8.1中仍然使用消息中的占位符!)。 Supported events are: Tapped , PointerPressed , Loaded , DataContextChanged , Click , Checked , Unchecked , SelectionChanged , TextChanged , Toggled , NavigationCompleted 支持的事件包括: TappedPointerPressedLoadedDataContextChangedClickCheckedUncheckedSelectionChangedTextChangedToggledNavigationCompleted

See https://msdn.microsoft.com/en-us/library/windows/apps/dn469361.aspx 请参阅https://msdn.microsoft.com/en-us/library/windows/apps/dn469361.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 转换器无法将类型'system.datetime'的值转换为在Windows Phone 8.1 Datepicker中键入'datetime' - Converter failed to convert value of type 'system.datetime' to type 'datetime' in windows phone 8.1 Datepicker 无法将“ MultiBinding”类型的实例添加到“ DoubleCollection”类型的集合中 - Cannot add instance of type 'MultiBinding' to a collection of type 'DoubleCollection' Windows Phone 8.1 DatePicker控件 - Windows Phone 8.1 DatePicker control 在Windows Phone 8.1上找不到类型System.Security.Cryptography.SHA256 - Cannot find type System.Security.Cryptography.SHA256 on Windows Phone 8.1 在Windows Phone 8.1模块System.dll中找不到类型System.ComponentModel.TypeConverter - Cannot find type System.ComponentModel.TypeConverter in module System.dll, Windows Phone 8.1 Windows Phone 8.1应用中的“模块mscorlib.dll中找不到类型System.Resources.ResourceSet” - 'Cannot find type System.Resources.ResourceSet in module mscorlib.dll' in windows phone 8.1 app 将子代添加到在Windows Phone 8.1之后的代码中创建的页面类型的元素中 - Add Children to element of type Page created in code behind Windows Phone 8.1 将日期绑定到DatePicker-Windows Phone 8.1 - Binding Date to DatePicker - Windows Phone 8.1 自定义DatePicker Windows Phone 8.1通用 - Customize DatePicker Windows Phone 8.1 universal 单击时显示Windows Phone 8.1 Datepicker - Windows Phone 8.1 Datepicker show on click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM