Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6961237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:30:17+00:00 2026-05-27T15:30:17+00:00

I have a ComboBox with 2 items whose contents are databound to 2 dependency

  • 0

I have a ComboBox with 2 items whose contents are databound to 2 dependency properties (Foo and Bar).
I have a button which increases Foo and Bar.
When I press this button, I see in the output window that Foo and Bar have indeed changed. Setting a breakpoint on the binding (SL 5 only) also proves this point.
But the value displayed on the ComboBox is not updated!
It is only updated when I click on the ComboBox or change the selected item via [TAB] and [DOWN].

I even tried to call UpdateLayout() on my ComboBox after the values update but to no avail.

Here’s my code for you to test.

Code behind:

using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;

namespace ComboBoxBindingTest
{
    public partial class MainPage : UserControl
    {
        public int Foo
        {
            get { return (int)GetValue(FooProperty); }
            set { SetValue(FooProperty, value); }
        }
        public static readonly DependencyProperty FooProperty =
            DependencyProperty.Register("Foo", typeof(int), typeof(MainPage), new PropertyMetadata(0));

        public int Bar
        {
            get { return (int)GetValue(BarProperty); }
            set { SetValue(BarProperty, value); }
        }
        public static readonly DependencyProperty BarProperty =
            DependencyProperty.Register("Bar", typeof(int), typeof(MainPage), new PropertyMetadata(0));

        public MainPage()
        {
            Foo = 0;
            Bar = 0;
            InitializeComponent();
            DataContext = this;
        }

        private void Step()
        {
            Foo++;
            Bar++;
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            Step();
            Debug.WriteLine("Foo: {0}", Foo);
            Debug.WriteLine("Bar: {0}", Bar);
        }
    }
}

XAML:

<UserControl x:Class="ComboBoxBindingTest.MainPage"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             d:DesignHeight="138"
             d:DesignWidth="188">

    <StackPanel Background="White">
        <ComboBox Width="120"
                  Height="23"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Center">
            <ComboBoxItem Content="{Binding Foo}"
                          IsSelected="True" />
            <ComboBoxItem Content="{Binding Bar}" />
        </ComboBox>
        <Button Content="Step"
                Width="75"
                Height="23"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Click="Button_Click" />
    </StackPanel>
</UserControl>

What am I doing wrong, here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:30:17+00:00Added an answer on May 27, 2026 at 3:30 pm

    The Silverlight Combobox is only updating it’s text when the selection is changes as you already experienced. You can create your custom Combobox which can change it’s text on different events. Or (as a not so nice workaround) you can re-select the currently selected item:

    private void button1_Click(object sender, RoutedEventArgs e)
    {
        Step();
        var selectedItem = combobox.SelectedItem;
        combobox.SelectedItem = null;
        combobox.SelectedItem = selectedItem;
        Debug.WriteLine("Foo: {0}", Foo);
        Debug.WriteLine("Bar: {0}", Bar);
    }
    

    EDIT: An alternative solution
    If you are not adding the combobox items manually but bind the combobox to a viewmodel collection you can achieve the same result (although the code will be quite different from what you have right now)

    ViewModel for the items:

    public class Item : INotifyPropertyChanged
    {
        private int foo;
        public int Foo { get { return foo; } set { foo = value; FirePropertyChanged("Foo"); } }
    
        public event PropertyChangedEventHandler PropertyChanged;
    
        public void FirePropertyChanged(string prop)
        {
            if (PropertyChanged != null) PropertyChanged(this, new  ropertyChangedEventArgs(prop));
        }
    }
    

    Code behind:

    public MainPage()
    {
    
        InitializeComponent();            
        Items = new List<Item> {new Item {Foo = 0}, new Item {Foo = 1}};
        DataContext = this;
        combobox.SelectedItem = Items.First();
    }
    
    public List<Item> Items { get; set; }
    
    private void Step()
    {
        foreach (var item in Items)
        {
            item.Foo++;
        }
    }
    

    XAML

    <ComboBox Width="120" x:Name="combobox"
            Height="23" 
            HorizontalAlignment="Center"
            VerticalAlignment="Center" ItemsSource="{Binding Items}" >
        <ComboBox.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding Foo}"/>
            </DataTemplate>
        </ComboBox.ItemTemplate>               
    </ComboBox>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a combobox from which i need to programmatically disable items depending on
I have a comboxbox defined like this (basically): <ComboBox x:Name=pageViewSize> <ComboBox.Items> <ComboBoxItem IsSelected=True>5</ComboBoxItem> <ComboBoxItem>10</ComboBoxItem>
I have a ComboBox whose xaml is as follows <ComboBox Name=ComboBoxDiscussionType IsEnabled={Binding ElementName=ComboBoxDiscussionType, Path=Items.Count,
In a ComboBox there are some items which have to be enabled and some
i have a combobox which is bound to a datatable column like this: ComboBox.DataContext
I have set a list of items in a combobox, but when I debug
I want to have a select-only ComboBox that provides a list of items for
I have a ComboBox with a label function like this one: private function fieldLabelFunction(item:Object):String
I have a ComboBox that I set up like this: this.cmbCustomerJob.DisplayMember = display; this.cmbCustomerJob.AutoCompleteMode
I have a datagrid whose itemsSource is bound to a multiconverter which uses a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.