我有一个列表框显示菜单,用户可以在应用程序中导航。选择一个ListBox元素将在菜单的右侧显示相应的UserControl。但是,其中一个菜单项(ABOUT)不应该是可以聚焦的,而只能执行一项任务(打开一个弹出窗口)。选定的项目应保持以前的状态。检测鼠标单击列表框项目与焦点设置为False
以下建议this link我已经尝试绑定相关列表框元素的焦点属性到虚拟机中的布尔属性。但是,我没有得到SelectedIndex属性的任何更新。
有没有办法解决这个问题?
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>
你可以使用['IsHitTestVisible '从MSDN](https://msdn.microsoft.com/en-us/library/system.windows.uielement.ishittestvisible(v = vs.110).aspx) – XAMlMAX
为什么你要wan如果您不想选择该项目,可以期待SelectedIndex属性得到更新吗? – mm8
我希望能够选择列表框项目,但不是该项目应该有焦点。对于其他项目,它们将导致MainWindow布局发生变化,但是ABOUT项目将打开一个弹出窗口。因此,关于项目有重点没有任何意义。 – Oystein