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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:27:00+00:00 2026-05-20T17:27:00+00:00

Hello I’m trying to change several controls’ property according to some environment variables and

  • 0

Hello
I’m trying to change several controls’ property according to some environment variables and i want to avoid creating a property for each control in the datacontext, so i thought using a converter which sets the property according to control name. Goal is to use one property for all controls:

<Grid.Resources>
   <local:NameToStringConverter x:Key="conv" />    
</Grid.Resources>

<TextBlock Name="FordPerfect" 
     Text="{Binding ElementName="FordPerfect" Path=Name, Converter={StaticResource conv}, Mode=OneWay}"/>
<TextBlock Name="Arthur" 
     Text="{Binding ElementName="Arthur" Path=Name, Converter={StaticResource conv}, Mode=OneWay}"/>
<TextBlock Name="ZaphodBeeblebrox" 
     Text="{Binding ElementName="ZaphodBeeblebrox" Path=Name, Converter={StaticResource conv}, Mode=OneWay}"/>

and …

public class NameToStringConverter : IValueConverter
{
    public object Convert(
     object value, Type targetType,
     object parameter, CultureInfo culture)
    {            
        if (MyGlobalEnv.IsFlavor1 && ((string)value).Equals("ZaphodBeeblebrox")) return "42"
        if (MyGlobalEnv.IsFlavor2 && ((string)value).Equals("ZaphodBeeblebrox")) return "43"
        if (MyGlobalEnv.IsFlavor1 && ((string)value).Equals("Arthur")) return "44"

        return "?";
    }

    public object ConvertBack(
     object value, Type targetType,
     object parameter, CultureInfo culture)
    {
        throw new NotSupportedException("Cannot convert back");
    }
}

I’m sure there’s a better and more elegant way… Any ideas?

  • 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-20T17:27:01+00:00Added an answer on May 20, 2026 at 5:27 pm

    The point of oneway databinding is just to decouple UI (XAML) from code (CS). Here, your code and UI are tied so tightly together that trying to do this through databinding is really not buying you anything. You might simplify things by writing a method that takes the data value and applies it correctly to each control – still tightly coupled (bad) but at least the code is condensed and easy to follow (less bad).

    What you should probably do though is not rely on the control name but define a ConverterParameter. See the bottom 1/3 of this article http://www.switchonthecode.com/tutorials/wpf-tutorial-binding-converters

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

Sidebar

Related Questions

hello friends i am trying to get a list of user id and want
Hello World :) I'm trying to write MIXINS for BOX-SHADOW property using SASS like
Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello I am trying to save a bitmap image in a basic image editor
Hello everyone i am trying to format the input number range with php number_format
Hello Guys I am trying to figure out why i am gettings this error
Hello , I am using arshaw fullcalendar v1.5.2 (only month view ) for property
Hello ever one I want to ask a question about file opening.I want to
hello creating a custom object may be a widely published topic, but my lack
Hello fellow developers... just to make sure, I want to ask this question: How

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.