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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T18:06:17+00:00 2026-05-21T18:06:17+00:00

I have two controls. The XAML’s are big and very similar. One difference is

  • 0

I have two controls. The XAML’s are big and very similar. One difference is this: they contain a listbox, in one control, it’s bound to {StaticResource X}, and is multiselect, the other is bound to {StaticResource Y}, and is not multiselect. The code-behinds are also very similar. How should I combine these two classes into one? I thought about creating a base class and deriving my 2 controls from it, but I have no idea how to do that with XAML. I know I could make it easier if I set the differing properties in code instead of XAML (in which case the XAML’s would become identical), but let’s consider that plan B. Silverlight has no StyleSelector, it seemed like a possible solution though. Maybe VisualStateManager could do it, except it sounds bad, because my problem has nothing to do with visuals, but maybe I could define 2 states anyway. Except I think SL doesn’t support binding in style definitions. Tough question for a beginner like me…

  • 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-21T18:06:17+00:00Added an answer on May 21, 2026 at 6:06 pm

    So, to sum it up, I want one control which can work in somewhat different modes, or states. The mode can affect XAML properties and code logic, too.

    It seems like VisualStateManager is very limited in which properties it can manipulate. But when the differences are only visual, it’s the best choice.

    When there are other differences in XAML, then the obvious choice is to omit those properties from XAML and set them in code, like in the ctor. A nicer way is to expose those properties as dependency properties in code, bind to those properties in the XAML of the user control, and then you can specify those properties in other XAML’s where you use this user control. When your control doesn’t care what’s in those properties, then it’s a good design choice, too. In my case, though, when setting up those differing properties should be the responsibility of the user control itself, not its parent, and I want to expose a single mode property only, it’s not good.

    For this case, the best way I found so far is this:

    • create a normal user control (XAML+code), expose the differing properties (simple, not DP’s) and bind to them in XAML
    • make this user control abstract, and possibly some properties, too
    • for each different mode the control needs to support, derive a class from this base control (code only, no XAML), provide implementations for the abstract properties
    • instead of using the base control in other places, use one of the derived implementations

    This way, you can easily specify from outside which mode you want your control to work in. The drawback is that it’s not easy to change the mode, since it’s not a property you need to change but the type and instance of the control.

    And finally, when there are code logic differences, too, then one way is exposing a mode property, or using the abstract class method I described above. For example, a button click handler function can be abstract, too.

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

Sidebar

Related Questions

I have XAML similar to this: <ListBox ItemsSource={Binding SearchCriteria, Source={StaticResource model}} SelectionChanged=cboSearchCriterionType_SelectionChanged> <ListBox.ItemTemplate> <DataTemplate>
I have two controls on a page, one is a search entry and submission
I have two UIDatePicker controls in my app, one configured with UIDatePickerModeDate and one
I have two User Controls already created now I want to use one as
I have two user controls, in one of them I have a textbox, i
I have created two custom controls. On the basis of features any one of
i have two silverlight user controls name region.xaml and session.xaml and i want to
I have a main window which hosts two views (user controls). One is UserControl1
I want to switch between my two user controls AddUsers.xaml (user control) and Viewusers.xaml(user
Is it possible to have two controls on one page side-by-side in Silverlight? It

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.