Question

I have a TabControl with three TabItems. In each of the TabItems is one ComboBox. If I switch through the TabItems the first entry of the ComboBoxes is selected. But I want that nothing is selected. How to do it?

Here are some screenshots:

After the first call of the form, there is nothing selected enter image description here

After the switch to the second tab, the first element of the combobox is selected enter image description here

Update: This is the code for this example

   <Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Width="525" SizeToContent="Height">
<Grid>
    <TabControl>
        <TabItem Header="Test 1">
            <ComboBox>
                <ComboBoxItem>Test 1</ComboBoxItem>
                <ComboBoxItem>Test 2</ComboBoxItem>
            </ComboBox>
        </TabItem>
        <TabItem Header="Test 2">
            <ComboBox>
                <ComboBoxItem>Test 1</ComboBoxItem>
                <ComboBoxItem>Test 2</ComboBoxItem>
            </ComboBox>
        </TabItem>
        <TabItem Header="Test 3">
            <ComboBox>
                <ComboBoxItem>Test 1</ComboBoxItem>
                <ComboBoxItem>Test 2</ComboBoxItem>
            </ComboBox>
        </TabItem>
    </TabControl>
</Grid>

No binding. A brand new project in Visual Studio Express 2010.

And here is the code behind:

using System.Windows;
namespace WpfApplication1
{
   public partial class MainWindow : Window
   {
      public MainWindow()
      {
        InitializeComponent();
      }
   }
}
Was it helpful?

Solution 2

With your help and a long journey through the web, I now know, that there is no way to avoid the behavior, that the first focusable child on tabitem gets focused, without some code behind :(

Thank you all for your answers, especially @makc for his advice, that the blue background means, that the combobox is focused.

OTHER TIPS

Well there is no error in the example code.

Is this code?

Try to remove any item is selected or if there is binding say it to give you an answer.

No error

Try setting the FocusVisualStyle to null for combobox -

            <ComboBox FocusVisualStyle="{x:Null}">
                <ComboBoxItem>Test 1</ComboBoxItem>
                <ComboBoxItem>Test 2</ComboBoxItem>
            </ComboBox>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top