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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T01:38:27+00:00 2026-06-13T01:38:27+00:00

How do I get the text bound to txtMessage from the second view model?

  • 0

How do I get the text bound to txtMessage from the second view model? When I had only one view model, the text was working fine. It does not work anymore when I moved the actual download code to second view model. Am I missing something? Any help appreciated.

Xaml:

<DockPanel DockPanel.Dock="Top">
    <TextBlock x:Name="txtMessage" DockPanel.Dock="Top" Margin="5" Text="{Binding viewModel1.Message}" />
    <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" Margin="5,5">
    <ProgressBar Width="300" Visibility="{Binding IsDownloading, Converter={converter:VisibilityConverter}}" IsIndeterminate="True" />
<Button Content="Cancel" />
</StackPanel>
</DockPanel>
<Button Content="Download" Width="120" Margin="0,0,5,0" Name="btnSubmit" Click="btnSubmit_Click" />

CodeBehind:

public partial class DownloadWindow: Window
    {
        DownloadWindowViewModel viewModel = new DownloadWindowViewModel();

        public DownloadWindow()
        {
            InitializeComponent();
            this.DataContext = viewModel;
        }

        private void btnSubmit_Click(object sender, RoutedEventArgs e)
        {
            viewModel.IsDownloading = true;
            viewModel.Download();

        }

    }

viewModel:

public class DownloadWindowViewModel: INotifyPropertyChanged
    {

        Thread downloadThread;
        public DownloadViewModel viewModel1;

        public DownloadWindowViewModel()
        {
            viewModel1 = new DownloadViewModel();
        }

        private bool _isDownloading; = false;

        public bool IsDownloading
        {
            get 
            { 
                return _isDownloading; 
            }
            set 
            { 
                _isDownloading; = value;
                OnPropertyChanged("IsDownloading");
            }
        }

        public void Download()
        {
            viewModel1.Download();

        }

        public event PropertyChangedEventHandler PropertyChanged;

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


    }

viewModel1:

public class DownloadViewModel: INotifyPropertyChanged
    {
        Thread _thread;

        public void Download()
        {
            ThreadStart threadStart = delegate()
            {
                StartDownload();
            };
            _thread = new Thread(threadStart);
            _thread.IsBackground = true;
            _thread.Start();

        }

        private void StartDownload()
        {
            for (int i = 10; i < 1500; i++)
            {
                Thread.Sleep(5000);
                Message = "Downloading " + i.ToString();
            }
        }

        private string _message = "";

        public string Message
        {
            get
            {
                return _message;
            }
            set
            {
                if (_message != value)
                {
                    _message = value;
                    OnPropertyChanged("Message");
                }

            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

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

    }
  • 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-13T01:38:28+00:00Added an answer on June 13, 2026 at 1:38 am

    Your viewModel1 has to be a property, and it’s a field at the moment. Change it to:

    public DownloadViewModel viewModel1 { get; set; }
    

    Explanation why such restriction exists, can be found here (primarily due to notification/verifications mechanisms simply not working for fields):

    • Why does WPF support binding to properties of an object, but not fields?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listbox bound to a view model observable collection: This works fine,
How to get text: Text example max from: <td valign=top align=left> <a href=/server?tree=xabaf class=normal>
is it possible to get text from images with tesseract asynchronously? id love to
I am trying to get text input from the keyboard in Java 6. I
I want to get text from current active line (the line where the caret
I have a string in C# and would like to get text from specific
This is an extension to the question I asked here: Get text from clipboard
My question is, how can I get text from header in javascript? So if
I have a text box which is bound to a data service to get
I would like to get text width of a string before an application starts.

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.