2017-10-04 6 views
1

ユーザーがアプリケーション内をナビゲートできるメニューを表示するListBoxがあります。 ListBox要素を選択すると、メニューの右側に対応するUserControlが表示されます。ただし、メニュー項目の1つ(ABOUT)はフォーカス可能ではなく、タスクを実行するだけです(ポップアップウィンドウを開く)。選択された項目は以前の状態に残るはずです。FocusableがFalseに設定されたListBox項目のマウスクリックの検出

次の提案this link関連するListBox要素のFocusableプロパティをVMのブール値プロパティにバインドしようとしました。しかし、私はSelectedIndexプロパティの更新を取得しません。

これを回避する手段はありますか?

ListBox displaying navigation options

XAML:

<ListBox Grid.Row="0" 
      ItemsSource="{Binding MenuButtonInfoList}" 
      SelectedIndex="{Binding SelectedMainMenuIndex, Mode=TwoWay}" 
      Background="Transparent" BorderBrush="Transparent" Padding="0" 
      VerticalContentAlignment="Center"> 
    <ListBox.ItemContainerStyle> 
     <Style TargetType="{x:Type ListBoxItem}"> 
      <Setter Property="Focusable" Value="{Binding Path=Focusable}" /> 
     </Style> 
    </ListBox.ItemContainerStyle> 
    <ListBox.ItemTemplate> 
     <DataTemplate> 
      <Border Style="{StaticResource MenuButtonBorder}"> 
       <StackPanel Orientation="Horizontal" Height="Auto"> 
        <Image Source="{Binding ImageFilePath}" 
          Style="{StaticResource MenuButtonImage}" /> 
        <Label Content="{Binding Label}" 
          Style="{StaticResource MenuButtonLabel}" /> 
       </StackPanel> 
      </Border> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 
+0

あなたは '[IsHitTestVisibleを使用することができます'MSDNから](https://msdn.microsoft.com/en-us/library/system.windows.uielement.ishittestvisible(v = vs.110).aspx) – XAMlMAX

+0

なぜあなたはうまくいきますかアイテムを選択できないようにするには、SelectedIndexプロパティが更新されることを期待していますか? – mm8

+0

ListBox項目を選択できるようにしたいが、項目にフォーカスがあるようにする必要がある。他の項目では、MainWindowレイアウトの変更が発生しますが、ABOUT項目はポップアップウィンドウを開きます。したがって、ABOUT項目に焦点が当てられていても意味がありません。 – Oystein

答えて

1

あなたは彼らが注目されていないようにそれらが見えるようにunfocusableアイテムのカスタムControlTemplateを定義することができます。

<ListBox.ItemContainerStyle> 
    <Style TargetType="{x:Type ListBoxItem}"> 
     <Style.Triggers> 
      <DataTrigger Binding="{Binding Focusable}" Value="False"> 
       <Setter Property="Template"> 
        <Setter.Value> 
         <ControlTemplate TargetType="{x:Type ListBoxItem}"> 
          <Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" 
               BorderThickness="{TemplateBinding BorderThickness}" 
               Background="{TemplateBinding Background}" 
               Padding="{TemplateBinding Padding}" SnapsToDevicePixels="true"> 
           <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
          </Border> 
         </ControlTemplate> 
        </Setter.Value> 
       </Setter> 
      </DataTrigger> 
     </Style.Triggers> 
    </Style> 
</ListBox.ItemContainerStyle> 
+0

悪い考えではありません。しかし、以前に選択された項目はフォーカスが失われるため、メニュー項目は選択されていないように見えます。私は、ある項目に焦点が合わないときには、その項目に対するクリックを検出することは可能であるが、以前に選択された項目にはフォーカスが残る可能性があると考えた。 – Oystein

+1

別の要素をクリックすると、フォーカスが失われます。それは焦点が働くことになっている方法です... – mm8

+0

"焦点が合っていない"アイテムを扱うときに、選択したアイテムを前に選択したアイテムに戻す方法を見つけなければなりません。 – Oystein

関連する問題