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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T19:33:01+00:00 2026-05-22T19:33:01+00:00

I have a textbox which I need to bind a string to. <TextBox Name=txtDoc

  • 0

I have a textbox which I need to bind a string to.

<TextBox Name="txtDoc" Margin="5" Text ="{Binding Source={x:Static local:DocumentViewModel.FileText}, Path=FileText}">

The FileText property is changed on a different class:

DocumentViewModel.GetInstance().FileText = File.ReadAllText(document.Path);

The DocumentViewModel is a class with Singleton:

public class DocumentViewModel : INotifyPropertyChanged
{
    private static string fileText;

    public string FileText
    {
        get { return fileText; }
        set
        {
            fileText = value; // Call OnPropertyChanged whenever the property is updated
            OnPropertyChanged("FileText");
        }
    }

   private void OnPropertyChanged(string filetext)
    {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
            handler(this, new PropertyChangedEventArgs(filetext));
        }
    }


    public event PropertyChangedEventHandler PropertyChanged = delegate { };

    private static DocumentViewModel instance = new DocumentViewModel();

    private DocumentViewModel() { }

    public static DocumentViewModel GetInstance()
    {
        return instance;
    }
}

I need to be able to change the value of the FileText property and reflect this change in the textbox.
It’s not working.
I tried using TextBox as a static property but then the Onp

  • 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-22T19:33:02+00:00Added an answer on May 22, 2026 at 7:33 pm

    Try to set the source to your viewmodel instead of the property itself, and set the instance property to public? {Binding Source={x:Static local:DocumentViewModel.instance}, Path=FileText}

    Edit: Included a complete example, that working for me:

    Xaml:

    <Window x:Class="Test.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Test"
        Title="MainWindow" Height="350" Width="525"
        Loaded="Window_Loaded">
      <TextBox Name="txtDoc" Margin="5"
               Text="{Binding Source={x:Static local:DocumentViewModel.Instance}, Path=FileText}" />
    </Window>
    

    Code-behind:

    public partial class MainWindow : Window
    {
      public MainWindow()
      {
        InitializeComponent();
      }
    
      private void Window_Loaded(object sender, RoutedEventArgs e)
      {
        DocumentViewModel.Instance.FileText = "Hello world!";      
      }
    }
    
    public class DocumentViewModel : INotifyPropertyChanged
    {
      #region Singleton implementation
    
      // Static constructor to create the singleton instance.
      static DocumentViewModel()
      {
        DocumentViewModel.Instance = new DocumentViewModel();
      }
    
      public static DocumentViewModel Instance { get; private set; }
    
      #endregion
    
      private static string fileText;
      public string FileText
      {
        get { return fileText; }
        set
        {
          if (fileText != value)
          {
            fileText = value;
            OnPropertyChanged("FileText");
          }
        }
      }
    
      #region INotifyPropertyChanged
    
      private void OnPropertyChanged(string filetext)
      {
        PropertyChangedEventHandler handler = PropertyChanged;
        if (handler != null)
        {
          handler(this, new PropertyChangedEventArgs(filetext));
        }
      }
    
      public event PropertyChangedEventHandler PropertyChanged;
    
      #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Asp.Net repeater, which contains a textbox and a checkbox. I need
I have an asp.net TextBox in which I want to check if the text
So I have columns defined like this: <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBox Text={Binding Path=COLUMN_NAME, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}
I have an ASP.Net 2.0 textbox which I need to be validated as having
I need to bind a TextBox's Text to a property of a class that
I need to have an input textbox in which I can click and the
i have a numerical textbox which I need to add it's value to another
I have a textbox which will contain phone numbers. I need to fill a
I have a dataset of values, which I need to put into a textbox.
I have a textbox which is extended by an Ajax Control Toolkit calendar. I

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.