• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C#/WPF data binding for collection

Status
Not open for further replies.

Merad

Platinum Member
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:
Apparently members have to be set up as properties before you can bind to them. I feel dumb now.
 
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.
Back
Top