我真的不能告訴什麼是從你的代碼錯不過,我強烈建議你使用史努比調試你的控件(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