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

  • SEARCH
  • Home
  • 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 541413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:20:26+00:00 2026-05-13T10:20:26+00:00

A converter such as what follows will cause the 2008 visual studio designer to

  • 0

A converter such as what follows will cause the 2008 visual studio designer to not display the xaml, and error out with a “Specified cast is not valid.” exception.

public class ItemsVisibilityToGridColumnWidthConverter : IMultiValueConverter
{
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
        //THE TWO OFFENDING LINES...
        var itemsVisibility = (Visibility)values[0];
        var orientation = (Orientation)values[1];

        if (orientation == Orientation.Horizontal && itemsVisibility != Visibility.Visible)
        {
            return new GridLength(0);
        }

        return new GridLength(4, GridUnitType.Star);
    }

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

Changing the cast to use a method such as this fixes the issue:

static class EnumCaster
{
    internal static Orientation CastAsOrientation(object value)
    {
        if (value is Enum)
        {
            return (Orientation)value;
        }
        return Orientation.Horizontal;
    }
    internal static Visibility CastAsVisibility(object value)
    {
        if (value is Enum)
        {
            return (Visibility)value;
        }
        return Visibility.Visible;
    }
}

My question is, wtf is wrong with the Visual Studio designer? And, is there a better way to cast these objects to their corresponding Enum in such a way that the designer doesn’t throw a fit?

  • 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-13T10:20:27+00:00Added an answer on May 13, 2026 at 10:20 am

    I think it might happen because at some point, the converter is called with bad arguments. You can debug the call the converter in the designer by following these steps :

    • start a new instance of Visual Studio
    • attach to the first VS instance (Tools -> Attach to process)
    • open the converter source file
    • put a breakpoint in the Convert method
    • reload the WPF designer in the first VS instance

    That way you should be able to examine the arguments passed to the converter

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

Sidebar

Related Questions

I have often encountered an error such as cannot convert from 'method group' to
I will read a sequential file which include some string such as 79.85, 1000,
Currently Virtuemart uses a converter module: convertECB.php . Such module fetches exchange rates from
Summary The C/C++ compiler in Microsoft Visual Studio gives warning C4090 when a C
I have an input string such as x=y|a=b|c=10 etc which gets converted to dynamic
Is there an actual package in CPAN to convert such string: my $string =
I have written this code to convert string in such format 0(532) 222 22
looking for the standard bug-proofed way to convert long names such as C:\Documents and
I am trying to convert a date with individual parts such as 12, 1,
I need to convert strings in Python to other types such as unsigned and

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.