Silverlightでは、上矢印または下矢印またはタブを押すと、現在ハイライト表示されている(選択されていない)項目の周りに小さなボックスが描画されます。私は、小さなボックスの周りにあるアイテムを見つけたいので、ユーザーがタブを押したときに選択したアイテムにすることができます。私はこれで3日間過ごしました。多分誰かがそれを使うことができます。Comboboxでハイライト(選択されていない)項目を検索
void SelectorRapidAccessKeyBehavior_DropDownOpened(object sender, EventArgs e)
{
FindPopup();
}
private void FindPopup()
{
CleanUpPopupHandler();
pop = GetPopup(base.AssociatedObject);
if (pop != null && pop.Child != null)
{
pop.Child.KeyDown += AssociatedObject_KeyUp;
foreach (FrameworkElement c in Finder.FindVisualChildren<FrameworkElement>(pop.Child))
{
c.KeyDown += new KeyEventHandler(c_KeyDown);
}
}
}
void c_KeyDown(object sender, KeyEventArgs e)
{
int t = this.AssociatedObject.TabIndex;
Border ci = sender as Border;
if (e.Key == Key.Tab)
{
if (ci != null)
{
//this here is the magic line
var v = Finder.FindVisualChildren<FrameworkElement>((DependencyObject)pop.Child).Where(a => a.Opacity > 0 && a.Name == "FocusVisualElement" && a.Visibility == Visibility.Visible);//&&)
object o = v.First().DataContext;
int i = this.AssociatedObject.Items.IndexOf(o);
if (i > -1)
this.AssociatedObject.SelectedIndex = i;
pop.IsOpen = false;
DependencyObject d = Finder.FindParent<FloatableWindow>(this.AssociatedObject);
if (d == null)
d = Finder.FindParent<Window>(this.AssociatedObject);
Control c = Finder.FindVisualChildren<Control>(d).Where(a => a.TabIndex > t).OrderBy(a => a.TabIndex).FirstOrDefault();
if (c == null)
c = Finder.FindVisualChildren<Control>(d).OrderBy(a => a.TabIndex).FirstOrDefault();
if (c != null)
c.Focus();
}
}
}
あなた自身の解決策を適切な回答として投稿し、質問から削除してください、それはそこに属しません。 –
未登録のアカウントを登録済みのアカウントにマージしました。この質問の所有権を持ち、直接編集することができます。 –
Timさん、ありがとうございました! –