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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:21:00+00:00 2026-06-02T02:21:00+00:00

Matt Hamilton told me an interesting fact about WPF: binding in two way mode

  • 0

Matt Hamilton told me an interesting fact about WPF: binding in two way mode with a static variable is possible in version 4.5.
Unfortunately V4.5 ist still beta, I decided to change my code to get my app finally run correct.

But – still I have similar problems, here we go:

I have a very simple class ‘RecallConnectionSettings’. This member of this class should be accessible from everywhere in the code, so I decided to make them static (like this):

public class RecallConnectionSettings
    {
            private static string Server {get;set;} 
    }

As you can see: there is only one variable ‘Server’.
Now what I want is to make 2WayMode binding from a TextBox Text-property to that ‘Server’ value.

So I tried this:

<UserControl....>
    <UserControl.Resources>
            <local:RecallConnectionSettings x:Key="recallConf"/>
    </UserControl.Resources>
    <TextBox Text="{Binding Source={StaticResource recallConf}, Path=Server,  
Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ... Name="txtServerAdress" />
</UserControl>

This works great when I change the value in the textbox – but not from the other side.
If I change the ‘Server’ value (by hand), the text-property in my textbox will not update.

Of course not – as I now know I have to implement INotifyProperty in my RecallConnectionSettings-class.
Then it looks like this:

 public class RecallConnectionSettings : INotifyPropertyChanged
    {
    public  event PropertyChangedEventHandler PropertyChanged;
    private static string s_server; 

    public static string Server
            {
                get { return s_server; }
                set
                {
                    s_server = value;
                    OnPropertyChanged("Server");
                }
            }

public static event PropertyChangedEventHandler PropertyChanged;



protected static void OnPropertyChanged(string name)
            {
                PropertyChangedEventHandler handler = PropertyChanged;
                if (handler != null)
                {
                    PropertyChanged(this, new PropertyChangedEventArgs(name));
                }
            }
    }

Well – this can’t work too. Because there are only static methods, I can’t use the class instance to call the event:

PropertyChanged(this, new PropertyChangedEventArgs(name));

So – what to do now?
I thought about using a singleton, so I did this:

public class RecallConnectionSettings : INotifyPropertyChanged
    {
        private static RecallConnectionSettings instance;

        private RecallConnectionSettings(){}

        public static RecallConnectionSettings Instance
        {
            get
            {
                if(instance == null)
                {
                    instance = new RecallConnectionSettings();
                }
                return instance;
            }
        }
// ... here comes the other stuff
}

To make it work, I also have to prepare my UserControl, so I did this:

...    
<UserControl.DataContext>
            <local:RecallConnectionSettings/>
</UserControl.DataContext>
...

At this point there is no need to go on trying, because for doing this, the default constructor must be public.

No matter what I am doing: it does not work.
Seems to me that I still do not understand how that works – would you be so kind and show me the trick ?

  • 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-06-02T02:21:02+00:00Added an answer on June 2, 2026 at 2:21 am

    Keep the singleton solution and replace this:

    ...    
    <UserControl>
        <UserControl.DataContext>
            <local:RecallConnectionSettings/>
        </UserControl.DataContext>
        ...
    </UserControl>
    ...
    

    By this:

    ...    
    <UserControl DataContext="{x:Static local:RecallConnectionSettings.Instance}">
       ...
    </UserControl>
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a version of Matt Gemmell's MGTwitterEngine, and I'm trying to get some
I'm reading a book about iOS (it calls Programming iOS 4, by Matt Neuburg)
Afer reading this topic C++ interview preparation (Matt's answer) I've got a question about
In Matt's post about drying up cucumber tests , Aslak suggests the following. When
I've got two Arrays: members = ["Matt Anderson", "Justin Biltonen", "Jordan Luff", "Jeremy London"]
I have a variable x (list)that looks like ['JACKIE:34', 'MATT:444', 'CEN:12', 'PETE:12', 'RANDY:92', 'MITCH:2',
using Matt's util code (a bit edited for Unicode text) public class GridViewExportUtil {
Upon launching a sinatra app, I get the following error message: /home/matt/.rvm/gems/ruby-1.9.3-p125/gems/backports-2.5.1/lib/backports/tools.rb:310:in `require': cannot
I have list elements like so: <li> <strong style=color: #BBB;>1</strong> <a href=>Matt</a> <b>4 days
I'm using Matt Gallagher's Audio Streaming Project . I downloaded the code/project and 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.