C#/WPF data binding for collection

Status
Not open for further replies.

Merad

Platinum Member
May 31, 2010
2,586
19
81
In the settings for my project I have a StringCollection. I'm trying to bind it to a listbox in one of my settings menus to let the user change the values.

I have no problem bind the actual resource to make the string populate the box, but apparently StringCollection doesn't support the appropriate notifications for two way binding. So, I've give the settings window an ObservableCollection<string> member, copy the contents over on open & close, etc. But I can't seem to figure out how to get that data member to work in binding... all the examples I can find seem to be for static data...

Edit: Just to be clear, I need something like this:

CS
Code:
public partial class MyWindow : Window
{
  private ObservableCollection<string> mystrings;

  ...
}

XAML
Code:
<Window x:Class="MyWindow"
...

  <ListBox ItemsSource="{Binding ??? what here ???, Mode="TwoWay"}"/>
</Window>
 
Last edited:

Merad

Platinum Member
May 31, 2010
2,586
19
81
Apparently members have to be set up as properties before you can bind to them. I feel dumb now.
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Don't feel dumb. WPF databinding is a convoluted abomination that stretches the definition of "markup" to the breaking point. If you have to do it anyway, you might find this handy...

http://www.nbdtech.com/Free/WpfBinding.pdf

I'm a big fan of WPF and the whole idea of declarative UIs for native clients, but I fail to see the advantage of binding over more procedural methods of initializing and updating UI elements. I'm good with it in its simplest forms, i.e. bind list to datasource, bind text field to property, all well and good. But I don't feel it was that hard to do it the old way, and it was a lot easier to understand.
 
Status
Not open for further replies.