WPF Data Binding TooWay XAML to C# and C# to XAML
NickName:Namek Ask DateTime:2012-12-27T00:45:21

WPF Data Binding TooWay XAML to C# and C# to XAML

I have XAML code:

<TextBox Name="textBoxMask1"/>
<TextBox Name="textBoxMask2"/>
<TextBox Name="textBoxMask3"/>
...
<TextBox Name="textBoxMask9"/>

and class in C#:

private static string mask1;
public static string Mask1
{
    get { return mask1; }
    set { mask1 = value; }
}

private static string mask2;
public static string Mask2
{
    get { return mask2; }
    set { mask2 = value; }
}

private static string mask3;
public static string Mask3
{
    get { return mask3; }
    set { mask3 = value; }
}
....
private static string mask9;
public static string Mask9
{
    get { return mask9; }
    set { mask9 = value; }
}

And I want to bind these TextBoxes with Properties -> textBoxMask1 with Mask1 etc. Earlier I did this by TextChanged, but I want to make Binding. TooWay Binding, because I want to predefine Mask1, Mask2, Mask3, ..., Mask9 in another C# class, and maybe later change these values - also in some C# code - and I want my changes, to be visible in layout (XAML) and in C# code - so ex. changing Property Mask1 from C# will change Text in TextBox textBoxMask1, and changing Text in textBoxMask1 will change Property Mask1. I don't understand, how to make connection (binding) between objects XAML and C#.

Copyright Notice:Content Author:「Namek」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/14043483/wpf-data-binding-tooway-xaml-to-c-sharp-and-c-sharp-to-xaml

More about “WPF Data Binding TooWay XAML to C# and C# to XAML” related questions

WPF Data Binding TooWay XAML to C# and C# to XAML

I have XAML code: &lt;TextBox Name="textBoxMask1"/&gt; &lt;TextBox Name="textBoxMask2"/&gt; &lt;TextBox Name="textBoxMask3"/&gt; ... &lt;TextBox Name="textBoxMask9&quo

Show Detail

WPF Binding XAML vs C#

I've got a strange problem - binding created through XAML (both ways by markup extension or normal) isn't working(BindingOperations.IsDataBound returns false and in fact there is no Binding object

Show Detail

WPF Binding Without XAML

I have a WPF app with a "Grid Window". This window has no added XAML to it. I create a grid (columns and rows) then place a rectangle in each one all in C#. This allows me to make a grid where I ...

Show Detail

Data binding WPF XAML

Hello I am new to WPF and I am not sure how to do the data binding and the code behind to get my textbox and button to be enabled and disabled. If you could show me how to get it to work in the ex...

Show Detail

WPF DataGrid binding to DataTable in XAML

I'm completely new to WPF/XAML. I'm trying to work out XAML code to bind a DataTable to DataGrid. What I have is an instance of custom DataContainer class which implements INotifyPropertyChanged. T...

Show Detail

Validate data binding in XAML in compile time

I’m working on WPF based application. Environment is VS2008 SP1 with .NET 3.5 SP 1. In our development we are using MVVM pattern widely. I.e. application developers write Models and ViewModels (...

Show Detail

Validate data binding in XAML in compile time

I’m working on WPF based application. Environment is VS2008 SP1 with .NET 3.5 SP 1. In our development we are using MVVM pattern widely. I.e. application developers write Models and ViewModels (...

Show Detail

WPF binding within binding in XAML

So I have a custom WPF UserControl called Row. It has a DependencyProperty called Index. The DataContext of Row is a class called ViewModel which contains an ObservableCollection. Within the XAML o...

Show Detail

C# - WPF - Binding Issue - Unable to bind C# properties in XAML

I'm just getting started with WPF in C#, currently using Visual Studio 2019, WPF application in .NET Framework 4.7.2. I've been struggling with data binding for a few days now, going through numerous

Show Detail

Binding a control to a data class using WPF/XAML

I am trying to bind a data class to a ListView control in WPF, but can't seem to get it working. I can bind it at run-time and get it working using the following: this.DataContext = DataSet; But...

Show Detail