views:

14

answers:

0

Below is the code to recreate the problem I'm having, the ComboBoxItems with TextBlock content, do not render correctly when bound to. Mousing over the ComboBox corrects the issue. So I have 2 questions. Why does the mouse over fix it? How do i have it correctly work with out the mouse over being required?

MainWindow.xaml

<Window x:Class="ComboBoxError.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
<StackPanel>
    <ComboBox SelectedValuePath="Tag" SelectedValue="{Binding Path=Property1, Mode=TwoWay}">
        <ComboBoxItem Tag="Good" Content="Good" />
        <ComboBoxItem Tag="Fair" Content="Fair" />
        <ComboBoxItem Tag="Poor" Content="Poor" />
        <ComboBoxItem Tag="Affected by limited food preference">
            <TextBlock TextWrapping="Wrap" Width="150" FontWeight="Normal">Affected by limited food preference</TextBlock>
        </ComboBoxItem>
        <ComboBoxItem Tag="Refused" Content="Refused" />
        <ComboBoxItem Tag="Not applicable or unable to assess">
            <TextBlock TextWrapping="Wrap" Width="150" FontWeight="Normal">Not applicable or unable to assess</TextBlock>
        </ComboBoxItem>
        <ComboBoxItem Tag="Other" Content="Other" />
    </ComboBox>
</StackPanel>

MainWindow.xaml.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ComboBoxError
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public Model Model = new Model();

        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = Model;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Model.Property1 = "Affected by limited food preference";
            //Model.Property1 = "Good";
        }
    }
}

Model.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ComboBoxError
{
    public class Model : INotifyPropertyChanged
    {
        private string _property1;

        public string Property1
        {
            get { return _property1; }
            set
            {
                _property1 = value;

                OnPropertyChanged("Property1");
            }

        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected void OnPropertyChanged(string propertyName)
        {
            if (this.PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}

Thanks for the help...