以編程方式選擇ListBox項目後,需要按下向上鍵兩次以移動選擇項。有什麼建議麼?在ListBox項目上設置焦點會中斷鍵盤導航
查看:
<ListBox Name="lbActions" Canvas.Left="10" Canvas.Top="10"
Width="260" Height="180">
<ListBoxItem Name="Open" IsSelected="true" Content="Open"></ListBoxItem>
<ListBoxItem Name="Enter" Content="Enter"></ListBoxItem>
<ListBoxItem Name="Print" Content="Print"></ListBoxItem>
</ListBox>
代碼:
public View()
{
lbActions.Focus();
lbActions.SelectedIndex = 0; //not helps
((ListBoxItem) lbActions.SelectedItem).Focus(); //not helps either
}
我已經選擇的項目在XAML「IsSelected =」真「我提供了代碼的其他選擇,因此它可能是更明顯的是我想做的事情。」 lbActions.SelectedIndex = 0;「。 – StreamT 2010-02-08 18:46:55
我的答案仍然有效,只需在* SelectedIndex = 0之後放置代碼* – Heinzi 2010-02-08 18:48:38
不要爲我工作,選擇的項目,這不是問題,鍵盤導航後無法正常工作 – StreamT 2010-02-08 18:52:19