3

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?

7
  • Nope. Something is way wrong there. Reinstall visual studio. Don't worry about trying to find a solution to this issue--there isn't one.
    – user1228
    Feb 12, 2015 at 14:56
  • Why? is this the only solution?
    – Utsav Dawn
    Feb 12, 2015 at 17:27
  • "The text associated with this error code could not be found" That's bad news. Serious bad news.
    – user1228
    Feb 12, 2015 at 18:41
  • I think the error is because of DateChanged in the EventName. I have changed it to Tapped and then its working fine. Can you tell is anything wrong with DateChanged event? Or any event close to this.
    – Utsav Dawn
    Feb 13, 2015 at 5:54
  • I have a very similar issue binding to a ColorHexagonPicker ColorChanged event. Could it be something to do with the events tied to those kind of changes? @Will can you explain further why that mesage may be bad news? Other bindings are working as Utsav said (I have the same error).
    – Poken1151
    Feb 23, 2015 at 3:42

1 Answer 1

3

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.