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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T03:47:28+00:00 2026-05-16T03:47:28+00:00

imagine the following simple Models (example for simplicity reasons; in fact, we have MVVM

  • 0

imagine the following simple Models (example for simplicity reasons; in fact, we have MVVM here but it doesn’t matter):

public class User {
  public string Username { get; set; }
}

public class StackOverflowUser : User {
  public int Reputation { get; set; }
}

Now we have a Silverlight UserControl which contains the following Controls (again, this is just an example, stripped down to the core):

<Grid>
    <TextBlock Text="Username:" />
    <TextBlock Text="{Binding Path=Username}" />

    <TextBlock Text="Reputation:" />
    <TextBlock Text="{Binding Path=Reputation}" />
</Grid>

Now I’d like this UserControl to be compatible with both Models, User and StackOverflowUser. I might set the UserControl’s DataContext to either a User or StackOverflowUser Type:

this.DataContext = new User { Username = "john.doe" };

If set to StackOverflowUser, everything works fine. If set to User, I’m getting a “BindingExpression Path error”, because the Property Reputation is missing in the User Model. Which I understand completely.

Is there any way to 1) avoid this
exception
and 2) control the
visibility
of the controls, collapse
when bound property is not available?

Of course, we prefer an elegant solution, where the problem is solved by tuning the Binding Expression and/or using Converters etc. and avoid tons of code behind if possible.

Thanks in advance for your help and suggestions,
best regards,

Thomas

  • 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-16T03:47:29+00:00Added an answer on May 16, 2026 at 3:47 am

    I finally got my problem solved. A co-worker finally implemented a solution including a workaround for WPFs DataTemplates DataType attribute (or generally, a DataTemplateSelector). It’s not very pretty (i guess, no workaround is) but it works. Unfortunately, i cannot post any code snippets because its closed-source. But i found some links afterwards, providing a pretty similar solution, like this one: Silverlight: a port of the DataTemplateSelector. If you have a similar problem, this will help you as well. Here or there are more thoughts on this subject.

    The actual solution is following Ozan’s hints. Unfortunately, his solution is not working so I don’t want to mark his comment as the accepted answer but I give at least an upvote.

    Thanks!

    best regards,

    Thomas

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

Sidebar

Related Questions

Imagine the following simple code: public void F<T>(IList<T> values) where T : struct {
Imagine the following REBOL code: foo: context [bar: 3] I now have a context
Imagine I have the following: inFile = /adda/adas/sdas/hello.txt # that instruction give me hello.txt
Imagine I have the following: private IEnumerable MyFunc(parameter a) { using(MyDataContext dc = new
Imagine we have a program trying to write to a particular file, but failing.
I have the following simple problem that I'd like to use to experiment with
Imagine you created the following simple widget with UiBinder: <!DOCTYPE ui:UiBinder SYSTEM http://dl.google.com/gwt/DTD/xhtml.ent> <ui:UiBinder
Imagine the following A type T has a field Company. When executing the following
Imagine the following tables: create table boxes( id int, name text, ...); create table
Imagine having the following scenario: You need to create a system where the Back

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.