Link to home
Start Free TrialLog in
Avatar of Joni Kettunen
Joni KettunenFlag for Finland

asked on

Adding one static value to bound ItemSource in XAML

Hi,

I have WPF program which uses basic binding when attaching items to a ComboBox. Data to this combo box is retrieved from server using a WCF service.

Is there a way to add "<select item>" value to source list at the client side?

Do I have to change how data is bound to be able to add "<select item>" as a default value to the selection list?

Could you please provide sample code?
<ComboBox x:Name="ComboBoxBranch"
          ItemsSource="{Binding Source={x:Static Application.Current}, Path=Branches}"
          SelectedItem="{Binding Branch}" />

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of lucky_james
lucky_james
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Joni Kettunen

ASKER

I'll look into those articles and get back after some testing.
I've tried some code samples and found out through search in web that:

"When the ComboBox control binds to DataSource, you  cannot update Items of it."
http://social.msdn.microsoft.com/Forums/en-US/winformsdatacontrols/thread/4d4462ba-f4d7-4f1d-8747-8fe63272a7f4

Only way to go around this restriction is to use some kind of wrapper which would modify the data source. In a ComboBox this isn't a problem because it doesn't update data directly back to database.

I can't find a way to wrap myself around that binding. I'd like to have some wrapper like

ItemsSource="{Binding  Source=AddSelectItemWrapper={{x:Static Application.Current}, Path=Branches}}"

or something like that. =)
Without code sample it required lot of work to find out the solution. However, suggested article was so well written that reading it was just a pleasure.

Still, the article didn't mention particular problem with ComboBox, you can't update its contents after binding. You have to change contents of source model and bind it again.