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 384611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T15:23:50+00:00 2026-05-12T15:23:50+00:00

As part of learning WPF I just finished working through an MS Lab Exercise

  • 0

As part of learning WPF I just finished working through an MS Lab Exercise called “Using Data Binding in WPF” (http://windowsclient.net/downloads/folders/hands-on-labs/entry3729.aspx).

To illustrate using an IMultiValueConverter, there is a pre-coded implementation of one where the boolean result is used to determine whether the data binding is relevant for the current user. Here is the code for the convert operation:

public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
        // var rating = int.Parse(values[0].ToString());
        var rating = (int)(values[0]);
        var date = (DateTime)(values[1]);

        // if the user has a good rating (10+) and has been a member for more than a year, special features are available
        return _hasGoodRating(rating) && _isLongTimeMember(date);
    }

And here is the wiring to use this in the XAML:

<ComboBox.IsEnabled>
    <MultiBinding Converter="{StaticResource specialFeaturesConverter}">
    <Binding Path="CurrentUser.Rating" Source="{x:Static Application.Current}"/>
    <Binding Path="CurrentUser.MemberSince" Source="{x:Static Application.Current}"/>
    </MultiBinding>
</ComboBox.IsEnabled>

The code runs fine, but the XAML designer will not load with a “Specified cast not valid.” error. I tried a couple of ways to not use a cast, one of which I left uncommented in the code above. The funny thing is a finished lab exercise provided by MS also has the error.

Does anyone know how to fix it to make the designer happy?

Cheers,
Berryl

  • 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-12T15:23:51+00:00Added an answer on May 12, 2026 at 3:23 pm

    Problem here is that you use Application.Current, which is different in Design mode and in runtime.

    When you open designer, Application.Current will not be your “App” class (or whatever you name it). Thus there are no CurrentUser property there, and your get that error.

    There are multiple ways to fix it. The easiest one is to check if you are in design mode:

    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
    {
      if (Application.Current == null ||
          Application.Current.GetType() != typeof(App))
      {
        // We are in design mode, provide some dummy data
        return false;
      }
    
      var rating = (int)(values[0]);
      var date = (DateTime)(values[1]);
    
      // if the user has a good rating (10+) and has been a member for more than a year, special features are available
      return _hasGoodRating(rating) && _isLongTimeMember(date);
    }
    

    Another approach would be not using Application.Current as a source for your binding.

    Hope this helps :).

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

Sidebar

Related Questions

I have just started using WPF and am having trouble data binding from the
I'm just learning WPF. I'm using VS 2008. I've added an Image control to
I've just started learning WPF MVVM using Prism and Unity. Decoupling the view from
I just uploaded my first ASP.NET (as part of my learning of vb.net) and
query level: beginner As part of a learning exercise I have written code that
I'm currently learning how to write a WPF application using the MVVM pattern. I'm
As part of learning ruby/rails, I'm trying to implement http://github.com/professionalnerd/simple-private-messages into my application from
As a part of learning process, I am writing simple IM app, using Remoting
As part learning exercise, part hobby project, I am implementing my own interpretation of
As part of learning jQuery, I decided to do a simple tic-tac-toe game in

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.