我真的不能告诉什么是从你的代码错不过,我强烈建议你使用史努比调试你的控件(http://snoopwpf.codeplex.com/)
通过按住Ctrl + Shift的鼠标指向哪里你ComboBox是应该抓住输入,你会立即发现谁有焦点,而不是你的组合框。
你甚至可以改变一个属性的值,真的是你最好的朋友调试模板!
编辑
我害怕,但你的代码已经发布的作品对我来说:
<Window x:Class="WpfApplication6.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:wpfApplication6="clr-namespace:WpfApplication6"
Title="MainWindow"
Width="525"
Height="350">
<Window.Resources>
<DataTemplate x:Key="myTemplate" DataType="{x:Type wpfApplication6:MyType}">
<Border>
<Grid x:Name="upperLayout">
<Grid x:Name="lowerLayout">
<ComboBox x:Name="combo"
Grid.Column="0"
ItemsSource="{Binding Path=Things}"
SelectedItem="{Binding Path=SelectedThing}">
<ComboBox.ItemTemplate>
<DataTemplate DataType="{x:Type wpfApplication6:MyThing}">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
</Grid>
</Border>
</DataTemplate>
</Window.Resources>
<Grid x:Name="grid">
<ContentControl x:Name="content" ContentTemplate="{StaticResource myTemplate}" Margin="58,79,71,40" />
</Grid>
</Window>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
Loaded += MainWindow_Loaded;
}
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
MyType type = new MyType()
{
Things = new List<MyThing>() {new MyThing() {Name = "aaa"}, new MyThing() {Name = "bbb"}}
};
content.Content = type;
}
}
public class MyType
{
public MyThing SelectedThing { get; set; }
public List<MyThing> Things { get; set; }
}
public class MyThing
{
public string Name { get; set; }
}
也许别的东西将它拧紧,如无钥匙风格或无论如何,发布更多您遇到问题的代码。
虽然当您更改SelectedItem时,SelectedThing会改变吗? – PoweredByOrange
可能相关http://stackoverflow.com/questions/1342200/wpf-combobox-not-responding-to-mouse – keyboardP
您是否尝试查看SelectionChanged是否被调用?只需添加事件作为方法和断点。 – Master117