Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 597297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:15:54+00:00 2026-05-13T16:15:54+00:00

This is my class that implements IValueConverter: [ValueConversion(typeof(int), typeof(Priority))] public class PriorityConverter : IValueConverter

  • 0

This is my class that implements IValueConverter:

[ValueConversion(typeof(int), typeof(Priority))]
public class PriorityConverter : IValueConverter
{

    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (Priority) (int) value;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}

It seems that this line of code throws an InvalidCastException:

return (Priority) (int) value;

(Priority being an enum) I put a breakpoint at the start of the method and the value of “value” is int:4 so I have no idea why this exception is being thrown.
Here are resources (where app_data=”clr-namespace:AssignmentOrganizer.App_Data”):

<app_data:PriorityConverter x:Key="PriorityConverter" />
<app_data:KindConverter x:Key="KindConverter" />

Here is the implementation:

<gridview:GridViewDataColumn Header="Priority" Width="100" DataMemberBinding="{Binding Priority, Converter={StaticResource PriorityConverter}}" />
<gridview:GridViewDataColumn Header="Kind" Width="100" DataMemberBinding="{Binding Kind, Converter={StaticResource KindConverter}}" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:15:54+00:00Added an answer on May 13, 2026 at 4:15 pm

    As discussed in the comments to the question, this occurs because what is actually being passed to your value converter is a Byte rather than an Int32. Unboxing casts must always be to the exact type; to determine that exact type, it’s worth checking value.GetType().Name using Debug.WriteLine or the Immediate window.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom class that implements that IComparable. This class is stored in
I have a custom class that implements ICollection , and this class is readonly,
Let's say I have a class that implements the IDisposable interface. Something like this:
I have a class that looks like this public class SomeClass { public SomeChildClass[]
I have a class that looks like this: public class TextField : TextBox {
I've got a class that looks something like this: public class Parent { public
I've got a simple java class that looks something like this: public class Skin
I have a Canvas class that implements VirtualizingPanel and IScrollInfo. This class is contained
So I'm working on this class that's supposed to request help documentation from a
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.