0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

指定コントロールが属しているTabControlのIsSelectedをTrueにする

Last updated at Posted at 2023-05-26

やりたかったこと

登録ボタンを押した時に入力エラーがあったコントロールにフォーカスを当てたい。
画面には複数のTabControlがあり単純にフォーカスを当てるだけだと表示されないので、
エラーコントロールがあるTabControlを選択する必要がある。

実装

private void SelectTabItem(DependencyObject obj)
{
    if (obj == null) return;

    var parent = LogicalTreeHelper.GetParent(obj);
    if (parent is System.Windows.Controls.TabItem)
    {
        var tab = parent as System.Windows.Controls.TabItem;
        tab.IsSelected = true;
    }
    this.SelectTabItem(parent);
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?