Click here to Skip to main content
15,884,628 members
Everything / Binding

Binding

Binding

Great Reads

by xllance
An approach to bind datagrids through ITypedList interface.
by Razi Syed
Easily bind a class to .NET data controls like GridView, FormView, etc., and get an updated object or list back in the code-behind effortlessly.
by Umer Qureshi
How to create a Custom Control so it can be used later and how to give access to some of it properties
by igkutikov
Binding Properties of non GUI elements that still implement INotify

Latest Articles

by Federico Alterio
Get rid of all that MVVM boilerplate code just to bind an expression to other properties
by Ajcek84
Complex bindings in XAML made almost as simple as in JavaScript frameworks
by NitinShrivastava
In this article, we will try to understand Data Binding in AngularJS
by Uriel Jacobson
Xaml Binding vs. XBind

All Articles

Sort by Score

Binding 

11 Apr 2013 by xllance
An approach to bind datagrids through ITypedList interface.
25 Apr 2012 by Razi Syed
Easily bind a class to .NET data controls like GridView, FormView, etc., and get an updated object or list back in the code-behind effortlessly.
1 Dec 2015 by Umer Qureshi
How to create a Custom Control so it can be used later and how to give access to some of it properties
24 Apr 2012 by Shahin Khorshidnia
HelloMy solution is not adequately standard but it works. I guess there is also a standard way that you can find ;)But my solution:public partial class MyUserControl: UserControl{ public readonly static DependencyProperty TextProperty = DependencyProperty.Register("Text",...
23 Jun 2012 by igkutikov
Binding Properties of non GUI elements that still implement INotify
19 Jun 2015 by ergohack
System.Data.SQLite is great, but was missing some BLOB support. Switching to the native source project was easier than expected and provided significant functionality benefits.
28 Mar 2012 by Michael Soloduha
Extends WPF framework with binding that supports runtime path parameters
16 Jan 2024 by Graeme_Grant
Because it expects a boolean value? Use an IValueConverter for binding conversions. Here is more information: Value conversion with IValueConverter - The complete WPF tutorial[^]
25 Mar 2015 by TarikHuber
Use STT (SQL Table Toolkit) to bind WinForm Controls to a DataGridview and to define ComboBox data sources
30 Jul 2015 by stibee
Did you tried x:static?See http://stackoverflow.com/questions/32395/accessing-static-fields-in-xaml[^]
25 Jul 2022 by Federico Alterio
Get rid of all that MVVM boilerplate code just to bind an expression to other properties
2 May 2023 by Graeme_Grant
When I hit an issue, sometimes I like to remove the noise and break out a small project that focuses on the main issue. I have done just that for you. Start a new WPF project with the name WpfDataGridComboBox and drop this code in and you can...
20 Nov 2011 by Mehdi Gholam
I have found a possible solution here : http://www.dotnetmonster.com/Uwe/Forum.aspx/winform-data-binding/1042/BindingSource-Filter-fails-when-datasource-derives[^]
18 Apr 2013 by Yvan Rodrigues
A simple but effective way for format bound data in XAML with the Windows Runtime
6 Jun 2013 by Alexander Dymshyts
The solution was very simple - I just added RelativeSource to my binding in Mode = FindAncestor. Code looks now so: ...
16 Aug 2013 by Clifford Nelson
WPF does not use decimal as far as I know for any internal values. Many times have to be careful about even using double since there are other properties that are used, like Size or Thickness.
9 Sep 2013 by Stephan Ehret
This is an alternative for "Bindable Converter Parameter"
13 Jan 2014 by OriginalGriff
Perhaps it would help is you added the new row to the table?DataTable.NewRow[^] just creates a new blank row with the correct schema / columns...
21 Jan 2014 by Sergey Alexandrovich Kryukov
Look at the XAML sample in the original MDSN documentation on System.Windows.Controls.GridView:http://msdn.microsoft.com/en-us/library/system.windows.controls.gridview%28v=vs.110%29.aspx[^].You need to use the XML element GridViewColumn with the attribute DisplayMemberBinding (again, see...
22 Nov 2021 by Maciej Los
Well, i'd suggest to move data biding into ucSignGen. Imagine, you can easily set/get an object related with UserControl. All you need to do is to create custom property: partial class ucSignGen { private SignalGenerator SigGen = new...
13 Sep 2011 by Wayne Gaylard
To start with, binding to datasets and datatables is not the best solution in WPF applications, you really should use ADO.Net and a DataReader to convert your database info into CLR objects, in this case an ObservableCollection. You can then bind you datagrid to the collection, rather...
13 Sep 2011 by Simon Bang Terkildsen
Make MainViewModel.Empdata public, and do not initialize it twice it's not an error just redundant.My article might also be able to help you now and in the futureDebugging WPF data bindings[^]It might be tricky to understnd if you're really that new to data binding in WPF, but you're...
13 Sep 2011 by somasekhar_37
am completely new to MVVM. I was trying to bind the data from sqlserver to the Datagrid in WPF and perform Edit, update and delete operations on it. now, am unable to bind the data from sqlserver to datagrid atleast using observable collection in MVVM.... someone please help me out to resolve it...
20 Nov 2011 by Sander Rossel
Hi folks,I have been working with Entity Framework and binding for quite a while now. When suddenly the following struck me: A BindingSource has Sort and Filter Properties.These are only supported when the bound Object Implements IBindingList or IBindingListView. A standard List does not...
29 Nov 2011 by Anoop Ananthan
You have not mentioned your delete command. In the properties of the adapter object check the delete command field.If there is no primary key for this table then you can not delete or update.
26 Nov 2011 by Nikil S
Try checking the properties of the TableAdapterManager update & delete commands to see if they are valid.If the table being affected has no primary key this can also cause this type of problem.Reference[^]
4 Feb 2012 by Lauren Lilly
It is not necessary to create a converter to bind a ComboBox to an object
20 Feb 2012 by SteveAdey
In your ViewModel define a property like:public IEnumerable Names{get{ return nameColumn.Split('|');}}Then bind your ComboBox ItemsSource to NamesOk, the ViewModel will look like: public class MainViewModel { private string...
2 Apr 2012 by Dean Oliver
Here's a simple example using that feature. Text="{Binding Path=ItemName, UpdateSourceTrigger=Explicit}" />// itemNameTextBox is an instance of a TextBoxBindingExpression be = itemNameTextBox.GetBindingExpression(TextBox.TextProperty);be.UpdateSource();
12 Jun 2012 by Vartan Khachatourian
hi expertsa collection of a dynamic object, i want to bind it to a datagird but it dosen't work. List items = new List();and binding code:this.DataGird.ItemsSource = items;this.DataGird.Items.Refresh();(datagird shows nothing)I want the datagird be auto...
17 Aug 2012 by Kenneth Haugland
There is only onw thing to do in such a case, you will have to use an IValueConverter:Data Binding Using IValueConverter in Silverlight[^]You could bind the second combobox to isenabled and do the appropiate convertions from the selected values of the second one :)
20 Sep 2012 by dbaseman
The problem is that you're attempting to modify the control before it has been initialized. To get it to work all you have to do is have the constructor inherit from the base class: public customcombobox() : base() { Binding binding = new Binding(); ...
20 Sep 2012 by Member 9346729
I figured out my problem. Didn't need to have the constructor inherit from the base it said it was redundant. The problem was actually in my converter. I use the same converter elsewhere in my code but when using it in the xaml it doesn't send it as a list it sends each individual item in the...
17 Dec 2012 by ashokmmrk
Hi,DataSet ds = new DataSet(); which contain database dataprotected void gridView_PageIndexChanging(object sender, GridViewPageEventArgs e){ Gen_Lic_Grid.PageIndex = e.NewPageIndex;//add dataset Gen_Lic_Grid.DataSource =ds; Gen_Lic_Grid.DataBind();}
19 Dec 2012 by Christian Graus
It sounds to me like you want to store your data in a collection that all your tabs bind to. That way, it's one data store that contains your data, and each tab renders from a common data source.
19 Dec 2012 by Jason Gleim
You need a data model class that exposes your data collections and selected items. It should implement the INotifyPropertyChanged interface and it should be static or implement the Singleton pattern if you will use it across multiple pages or views.That class should expose your data...
23 Dec 2012 by akak6
For some reason I am having a heck of a time getting my TabControl to display properly when binding the ItemsSource to a ObservableCollection of view models. I'm basing my design off of the tutorial found here: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx. I did find a few questions...
24 Dec 2012 by Rddezh
Hi!You should use the SendKeys. It simulates the keyboard presses. SendKeys.Send("xxx@hotmail.com");The only problem is, how will you get information if F1 key is pressed. If your aplication is not focused that could not work. You should try, I'm not sure about...
20 Jan 2013 by Sergey Alexandrovich Kryukov
You need to execute the command in a separate thread. The only problem is that the intermediate results of the command execution might need to interact with the UI.You cannot call anything related to UI from non-UI thread. Instead, you need to use the method Invoke or BeginInvoke of...
4 Mar 2013 by Paulo Zemek
First, I agree that you are no using OOP, but let's focus on your problem.You do:Animal animalObj = null;But you never do:animalObj = something...I think your animalManager.GetSetAnimalInfo should look more like:animalObj = animalManager.GetSetAnimalInfo.After all,...
3 Jun 2013 by Alexander Dymshyts
Hi all,I have following xaml code where I am trying to bind converterParameter value: ...
5 Aug 2013 by hari111r
Hi i am using xceed datagrid i have two datagrid i want to reflect the changes in one datagrid to another. Using binding i have done for Width, Visible, VisiblePosition properties of datagrid column like below Width="{Binding Source={x:Reference StatusColumn},...
13 Aug 2013 by ridoy
Check these solutions,possibly your problem would be solved.insert item in combobox after binding it from a Dataset in c#[^]Add Custom Item after Databinding[^]WinForm ComboBox add text “Select” after data binding[^]
2 Oct 2013 by Jegan Thiyagesan
you create a tabViewModel, in the tab view model you create the collection of user control. so each control in the collection will have its own instance and be bind to each tab. This way you will maintain the separation.App.xaml ( set the App.xaml to fire the start up event)
11 Oct 2013 by ASP.NET Community
Windows Communication FoundationWindows Communication Foundation (WCF) is an SDK for developing and deploying services on Windows. WCF provides a
31 Oct 2013 by Wes Payne
I'm working on an established project that's based on WCF. It uses routing in order to expose a REST-ful API. Recently I had to change the behavior of one of the included services in order to return larger JSON-serialized responses without crashing. The change was trivial to make using a...
26 Oct 2013 by Kumartyr
i am binding data in Gridview control in page load event how to get a selected column's data in a string from the Gridview control (ie)It is the primary key of that table,so for every row selected by user there will be a primary key ID column bounded to it..... so i need to get that ID...
13 Jan 2014 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
You need to bind the DGV again like below.private void addNewRowButton_Click(object sender, EventArgs e){ csvData.NewRow(); // Provide Column values for the New Row. DataGridView1.DataSource = csvData; DataGridView1.DataBind();}
18 Apr 2014 by Shai Vashdi
Hi Shashank,Maybe you don't need MVVM. You should use MVVM only when you are writing a Business-Logic + UI and you want to separate them.If you are writing a control with UI-Logic you don't need to use MVVM! For example, lets say I've created a "Property Grid" control that reflects...
20 Apr 2014 by Shai Vashdi
Hi,This is my solution for the problem:MainWindow.cs:
19 May 2014 by Chathur
I have a DataGridView on the UI (a win form) and model objects stored in a List are shown in the Grid.Since this is MVP pattern, the DataSet returned from the service is converted to a list of Models (Earning) by the manager class and then the it's passed to the view by the presenter as a...
5 Jul 2014 by CHill60
Firstly have a look at that sql command select * from Course Number and NameWhat is the name of the table? As far as SQL is concerned then it is "Course" and "Number and Name" just throw an error - which is why you don't get your combobox populated.If you really must use spaces in your table...
17 Oct 2014 by Sergey Alexandrovich Kryukov
I call it "CBS" (Compulsory Binding Syndrome). The solution is:labelKey.Content = value;// Do I even have to explain why?Of course, you need to add the attribute Name="labelKey" in XAML line with label declaration: ....
29 Nov 2014 by Maciej Los
Steps to do:1) Create class:Public Class Customer Private sName As String = String.Empty Private sAddress1 As String = String.Empty Private sAddress2 As String = String.Empty Private sPhone As String = String.Empty Private sFax As String = String.Empty Private...
5 Feb 2015 by Peter Leow
It behaves in the way that was instructed by the code. You have mixed the 2 div's in one function and attached a second click events to each of them. The result is all mixed up. I have cleaned it up, take a look:var staff = $("#stuff");var staff1 = $("#stuff1");var staff2 =...
22 Feb 2015 by RajeeshMenoth
In ur ddl code add this one : ddlcountry.Items.Insert(0, "-Select-");
22 Feb 2015 by stibee
Proper solution is that your viewmodels implement INotifyPropertyChanged and you use ObservableCollection
28 May 2015 by F-ES Sitecore
Just write the data direct to the page @Model[i].Last_Name
31 May 2015 by anynameformecodeproject
to solve this problem write your code like this. public override string Text { set { base.Text = value; this.OnTextChanged(EventArgs.Empty); } get { return...
30 Jul 2015 by Maciej Los
Not sure i understand you well (because of this: "the required direction is from the UI to the property; The other direction is not required, but doesn't make a difference"), but...I'd suggest to read this: Static Classes and Static Class Members (C# Programming Guide)[^] - Static Members...
19 Aug 2015 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
Make a query to the second table by passing the customer id selected.So you will get two rows. Read the code values one by one by reader. Inside reader, use CheckBoxListId.FindByValue(code) to get the checkbox with that code. Then select it.
11 Jan 2017 by Jon McKee
Took me a second but I think I know what's going on here. The Source should be set to the object (or parent) which contains the property you wish to access while the Path is the path to that property from the source. Trynew Binding{Source = this,Path = new PropertyPath ( "PortSettings"...
27 Feb 2017 by jimmson
Hi Patrick,from our conversation I would suggest to use ItemsControl. This WPF control has ItemsSource property that you can bind to your list of customers/contacts and is easy to style and set ItemTemplate. It requires to learn how to do it but it's not difficult and you will get rid of the...
27 Feb 2017 by Pete O'Hanlon
Hi Patrick - it sounds like you're describing the scenarios supported by IEditableCollectionView. This allows you to swap backwards and forwards between a display template and an editable template. I describe how to deal with this here[^].
30 Mar 2017 by Richard Deeming
As mentioned in the comments, the ProgressValue class needs to implement INotifyPropertyChanged, and raise the PropertyChanged event when the State property changes.public class ProgressValue : INotifyPropertyChanged{ private bool _state; public event...
23 Jun 2017 by J. Calhoun
So the problem that I think you are having is the fact that you are modifying the entry in the database, but you are not updating the entry in the collection itself. In your Modify() function you are are fetching the current user from the database, not the collection itself. I would try to...
11 Jul 2017 by cha1i
Thanks for your replies all! I managed to make it work in two different ways: I tried Richard's solution, but did not work. But with a little tweaking it did: Return data.Surveys.Include("Outcome").ToList() Then I read this article: Lazy, Eager, and Explicit Loading of Related Data and...
21 Mar 2018 by Clifford Nelson
I believe your problem is that you set the value of PO_TITLE1 after the binding and the class PODetail has been set. You will have to implement the INotifyPropertyChanged in the PurchaseOrderModel class and trigger the PropertyChanged Event when the PO_TITLE1 value is changed.
11 Sep 2018 by Clifford Nelson
The INotifyPropertyChanged is intended to communicate from a ViewModel to the View, and uses a lot of external logic. You could do all the stuff with creating a Binding, but it would probably be far easier to just have the model execute an event whenever a change occurs that is observed by both...
2 Nov 2018 by 0x222fe
Thanks to @RichardDeeming, I got my final solution: ...
7 Nov 2018 by M.Kamran Asim
What do you mean by combobox value. do you mean enable-diable combo box has list of items or not. If this is the case, you can use following code public class ComboBoxEnableConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter,...
11 Nov 2018 by M.Kamran Asim
OK First Create a public ListItem property and Bind it to TextBox public ListItem SelectedItem { get=>selectedItem; set { selectedItem=value; RaisePropertyChange(); } } Second...
6 Mar 2019 by Gerry Schmitz
Create a class for your "string" and "width". Load a collection (List or ObserveableCollection) with instances of that class. Set the ItemSource to this collection. Bind the TextBlock "Text" and "Width" to the corresponding properties of the new "string and width" class. (What you're...
22 Aug 2019 by Member 14164795
How do I clear the bind on these properties so that changes I'm trying to make in an onpost method pull through? I have 6 bound properties in a ShipmentModel: [BindProperty(SupportsGet = true)] public ShipmentModel Shipment { get; set; } public class ShipmentModel { public string...
11 Mar 2020 by Richard MacCutchan
Data binding overview - WPF | Microsoft Docs[^]
14 Apr 2020 by Maciej Los
Quote: how we can show calendar data from the database to calender in c# winform. Take a look here: Select a Range of Dates in MonthCalendar Control - Windows Forms | Microsoft Docs[^] Display Specific Days in Bold with MonthCalendar Control -...
9 Nov 2021 by DoingWork
Hi Friends I have 2 different user controls i.e. ViewAUserControl.xaml , and ViewBUserControl.xaml . These controls are added dynamically in dynamic tabItems where each tabItem contains any single userControl from availabe 2 UserControls, whom...
20 Jan 2021 by Christian Graus
Once you add a datagrid, you can label the columns anyway you want and it's possible to foreach over an enum foreach (Suit suit in (Suit[]) Enum.GetValues(typeof(Suit))) { }
7 Jun 2021 by Richard Deeming
In the code you've shown, allGroup is a private field. WPF binding only works with public properties. If you check the output window in Visual Studio, you should see at least one binding error telling you that the property allGroup could not be...
26 Aug 2021 by dj4400
I found a solution: The comboBoxType binding should be declared like that: //Clicking the combo box now shows all the enum values comboBoxType.DataSource = Enum.GetValues(typeof(EnumItemType)); //the selected item of the combo box now...
2 Feb 2022 by Richard Deeming
You are changing an element within an array. That will not raise any "property changed" events, so the UI has no idea that the binding needs to be updated. Try replacing your array with an ObservableCollection: public...
2 Mar 2022 by Graeme_Grant
I did a quick Google Search:wpf treeview binding[^] And found this for you: TreeView, data binding and multiple templates - The complete WPF tutorial[^]
9 Aug 2022 by Graeme_Grant
1. This is trying to point to a Collection of type Tags on the DataContext of the MainWindow. You have set it to...
25 Aug 2022 by Graeme_Grant
Have you checked your binding? Here is a quick test showing the binding working: 1. Model: public class DataRecord { public int ID { get; set; } public string? Name { get; set; } public string? Description { get; set; } public...
3 Apr 2023 by Graeme_Grant
You are using MVVM. You can use DataBinding to track selection. 1. Wrap the Model: public class CheckItemModel : ObservableObject { private bool isChecked; public bool IsChecked { get => isChecked; set => Set(ref...
6 Mar 2024 by Graeme_Grant
List is not a bindable collection. You need to use the ObservableCollection Class (System.Collections.ObjectModel) | Microsoft Learn[^]. Here is a working solution for a similar question. Create a new project and add this code: 1. Classes: ...
11 Jul 2011 by Vishwanath Narayanan
This article will discuss about the real world problem and then we will see that how it can be resolved using JAXB.
6 Oct 2011 by Mastersev
Hey Guys,Assigning the Linq query result to the DataGrid datasource it takes a lot of time (40 seconds) and I only have 8000 entries (rows)in the XML file. I know that this can be fixed by looping through the Linq result elements and adding them to the grid view one by one but is there any...
6 Oct 2011 by Mastersev
Setting t he AutoSizeColumnsMode = False; & AutoSizeRowsMode = False; solved it. Now it loads 10000 records in 2 seconds!
11 Oct 2011 by Member 7782210
Learning the ropes of WPF data binding.. What's wrong with the following simple binding?I have a window with some instances of a user control: ItemsSource="{Binding...
10 Oct 2011 by Dave Kerr
Hi,You need to have a datacontext set properly - unfortunately your code examples have become a little bit garbled, is there any chance you can update the question with a bit more code?We need to see what the CommandRow object is.In essence you should have a viewmodel class that...
13 Oct 2011 by Renat Khabibulin
HiIt is MVVM project. I have a ListBox with TabControls inside of it's items. TabItems are different for each TabControl and are binded from ViewModel: Tabs are: public ObservableCollection Tabs { get { return tabs; } ...
13 Oct 2011 by Shmuel Zang
I tried to understand your problem and, I hope I guessed right.If you work MVVM and you change DataContext's, you probably have a view-model that contains the different view-models and the code that changes the DataContext's.Binding SelectedIndex or SelectedItem to the current view-model...
13 Oct 2011 by Renat Khabibulin
I have solved the my issue.The problem was that I used controls as DataContext:- List of TabItems- Controls inside TabItems contentThere was some processes, that I dont undrstand entire. But, idea is that while DataContext's changing, one DataContext can be assigned to 2 different...
17 Oct 2011 by Renat Khabibulin
HiI have met following problem. I use DataGrid and MVVM pattern. When bound collection become empty I get exception:The specified Visual is not an ancestor of this VisualSame problem is here: http://wpf.codeplex.com/workitem/9699[^]But nobody wrote about solution there...And...
17 Oct 2011 by Ganesan Senthilvel
In the same web reference, Alexis from WPF team, accepted as the bug and will be fixed in the future releases. With this info, you can reach out WPF team.
2 Nov 2011 by bizzare1988
Hi,This might be a silly question but im a beginner so im not sure. I have 3 lists and i am displaying them on 3 different listboxes in a listview as follows: public System.Collections.ArrayList name { get { return _name; }...
2 Nov 2011 by Pandya Anil
Kindly check the data is there while binding your collection..
2 Nov 2011 by Shmuel Zang
Did you set the DataContext of your window?If you declared the properties in the window's class, you can set the DataContext to the window. Just add this line:DataContext = this;to the constructor of the window's class.But, it is better to declare the properties in a different class and,...