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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:38:51+00:00 2026-06-12T15:38:51+00:00

I need to bind the text property of a textbox that it is located

  • 0

I need to bind the text property of a textbox that it is located in a secondary window to a property that is defined in the corresponding view model of that secondary window

XAML CODE:

<Window x:Class="RG.IOManager.Views.PreferencesDialog"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:genericClasses="clr-namespace:RG.IOManager.GenericClasses"
    xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
    Title="Setup" Height="131" Width="332"
    WindowStartupLocation="CenterOwner" 
    ShowInTaskbar="False"
    WindowStyle="ToolWindow"
    >

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../ResourceDictionary.xaml" />
            <ResourceDictionary Source="../ScrollBarTemplate.xaml" />
            <ResourceDictionary Source="../Styles.xaml" />
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>

<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="Auto" />
        <ColumnDefinition Width="10*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Label Content="Cycle Time"  Grid.Row="0" Grid.Column="0" Height="28" HorizontalAlignment="Left" Margin="10,10,0,20" Name="label1" VerticalAlignment="Top" />
    <StackPanel Grid.Row="0" Grid.Column="1" Width="190" Orientation="Horizontal">
        <!--
        <xctk:IntegerUpDown  Name="TbMainCycleTime" Margin="10,10,0,20" Width="50" Height="25" HorizontalContentAlignment="Right" 
                             Increment="1" Maximum="5000" Minimum="0" ShowButtonSpinner="False"/>
        -->

        <TextBox Name="TbMainCycleTime" Margin="10,10,0,20" Width="50" Height="25" HorizontalContentAlignment="Right" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" Style="{StaticResource textBoxErrorTooltip}" >
            <TextBox.Text>
                <Binding Source="PreferencesDialog" Path="CycleTime" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" >
                    <Binding.ValidationRules>
                        <genericClasses:IntegersValidation Min="0" Max="1000" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>

        <!--<TextBox Name="TbMainCycleTime" Margin="10,10,0,20" Width="50" Height="25" HorizontalContentAlignment="Right"  />-->
        <Label Content="ms" Margin="1,10,10,20"/>
    </StackPanel>
    <StackPanel Grid.Row="1" Grid.Column="1" Width="190" Orientation="Horizontal">
        <Button Content="Update" Height="23" HorizontalAlignment="Left" Margin="5,0,10,0" Name="btUpdate" VerticalAlignment="Top" Width="75" Click="btUpdate_Click" />
        <Button Content="Cancel" Height="23" HorizontalAlignment="Left" Margin="5,0,10,0" Name="btCancel" VerticalAlignment="Top" Width="75" Click="btCancel_Click" />
    </StackPanel>
</Grid>

CS CODE:

/// <summary>
/// Interaction logic for PreferencesDialogue.xaml
/// </summary>
public partial class PreferencesDialog : Window, INotifyPropertyChanged
{
    #region Binding Properties

    public event PropertyChangedEventHandler PropertyChanged;

    /// <summary>
    /// Main cycle time
    /// </summary>
    public int CycleTime
    {
        get { return _CycleTime; }
        set
        {
            _CycleTime = value;
            var handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs("CycleTime"));
            }
        }
    }
    private int _CycleTime;

    #endregion


    private IOManager _receiver;

    public PreferencesDialog(IOManager receiver)
    {
        this._receiver = receiver;
        InitializeComponent();

        //this.TbMainCycleTime.Text = _receiver.globalBindingProperties.MainCycleTime.ToString();
        this.CycleTime = _receiver.globalBindingProperties.MainCycleTime;
    }


    private void btUpdate_Click(object sender, RoutedEventArgs e)
    {
        _receiver.globalBindingProperties.MainCycleTime = Convert.ToInt32(this.TbMainCycleTime.Text);
        this.Close();
    }

    private void btCancel_Click(object sender, RoutedEventArgs e)
    {
        this.Close();
    }
}

Can someone help me to find what i did wrong? Thanks in advance

  • 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-12T15:38:52+00:00Added an answer on June 12, 2026 at 3:38 pm

    your approach is wrong. however if you change these two thing your problem will be solved:

    first set DataContext of the Window:

        public PreferencesDialog(IOManager receiver)
    {
        this.DataContext = this;
    
        this._receiver = receiver;
        InitializeComponent();
    
        //this.TbMainCycleTime.Text = _receiver.globalBindingProperties.MainCycleTime.ToString();
        this.CycleTime = _receiver.globalBindingProperties.MainCycleTime;
    }
    

    second remove ‘Source’ from TextBox.Text.Binding since the source is the dataContext.

        <TextBox Name="TbMainCycleTime" Margin="10,10,0,20" Width="50" Height="25" HorizontalContentAlignment="Right" Validation.ErrorTemplate="{StaticResource ErrorTemplate}" Style="{StaticResource textBoxErrorTooltip}" >
            <TextBox.Text>
                <Binding Path="CycleTime" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" >
                    <Binding.ValidationRules>
                        <genericClasses:IntegersValidation Min="0" Max="1000" />
                    </Binding.ValidationRules>
                </Binding>
            </TextBox.Text>
        </TextBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to bind a TextBox's Text to a property of a class that
I need to bind width property of the GridView column that is created dynamically
I need to bind a textblock.text property to a single element in an observable
I bind keyDown , keyPress and keyUp events to a text input. I need
I need to bind a property of a UserControl directly to another control, rather
I need to bind a property to an edit control and have the control
I have Window. Window.DataContext = DataRow. and i have TextBlock. I need to bind
I'm trying to bind a TextBlock's Text property in a very dynamic way. I
I had binded DataGrid to my collection, and i need bind height of each
I need to bind my socket to specific local IP before connecting as a

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.