在Windows Phone 8.1 DatePicker中出现了“无法将类型为'%0'的实例添加到类型为'%1'的集合”错误。

3

嗨,我正在使用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);
    }

有人能帮我解决这个错误吗?


不行,那里肯定有严重的问题。重新安装Visual Studio吧。别担心要找到解决方案——其实是没有的。 - user1228
这为什么是唯一的解决方案? - Utsav Dawn
与此错误代码相关联的文本无法找到。这是一个坏消息。非常糟糕的消息。 - user1228
我认为错误是由于事件名称中的DateChanged引起的。我已将其更改为Tapped,然后它正常工作了。你能告诉我DateChanged事件有什么问题吗?或者是否有任何类似的事件? - Utsav Dawn
这里没有什么“严重错误”。不要卸载Visual Studio。也许这会有所帮助http://stackoverflow.com/questions/24309546/problems-adding-blend-behavior-to-datepicker - H77
显示剩余2条评论
1个回答

3
我的回答可能有点晚,但是这个错误(在WinRT 8.1中仍然)会发生(消息中仍然有占位符!),如果你尝试添加的事件不存在或不被EventTriggerBehaviour支持。支持的事件包括:TappedPointerPressedLoadedDataContextChangedClickCheckedUncheckedSelectionChangedTextChangedToggledNavigationCompleted
请参见https://msdn.microsoft.com/en-us/library/windows/apps/dn469361.aspx

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接