views:

55

answers:

1

Hi, I would like to allow users to choose a Font Size from a ComboBox, but i would also like them to be able to enter the size by there own, i tried out the property: "IsEditable" (and changed it to true as value) of the ComboBox, but when i enter something that isn't in the ComboBox items (for example: my items are- 2,3,4;and i entered- 6), it shows me the following message: "Object reference not set to an instance of an object".

Thanks in advanced, Din

+1  A: 

Next time post your source code with question.

    public partial class MainWindow : Window
    {
        public class SomeItem
        {
            public int[] Numbers { get; set; }
            public string ChosenText { get; set; }
        }

        private SomeItem item;

        public MainWindow()
        {
            InitializeComponent();
            this.item = new SomeItem{Numbers=new[]{7,8,10}, ChosenText="10"};
            this.testStackPanel.DataContext = item;
        }

        private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            MessageBox.Show(item.ChosenText);
        }
    }

    <StackPanel VerticalAlignment="Center" x:Name="testStackPanel">
        <ComboBox IsEditable="True" Width="100" ItemsSource="{Binding Numbers}" Text="{Binding ChosenText}"/>
        <Button Content="Selected Value" Margin="0,10,0,0" Width="100" Click="Button_Click"/>
    </StackPanel>

I suggest the issue is in ComboBox.Text property.

vorrtex
thank you very much, will try
dinbrca