Silverlight ListBox自定义键盘选择行为

时间:2011-07-27 04:37:20

标签: silverlight listbox keyboard selection behavior

我正在自定义一个模板化的多选启用ListBox,并且无法轻松实现以下功能 - 如果只选择了一个当前(聚焦)的项目,当用户在列表中向上或向下导航时,选择应该是按照当前项目。我试图订阅DataTemplate的StackPanel的GotFocus事件,但显然我没有收到这些事件(即使MouseEnter / MouseLeave工作)。

我想我可以通过修改somewhat similar behavior来做到这一点,但是不是更方便吗?这看起来像是一个非常基本的行为......

<ListBox>
    <ListBox Name="lbItems" SelectionMode="Multiple">

    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal" 
                        MouseEnter="UIElement_OnMouseEnter"
                        MouseLeave="UIElement_OnMouseLeave"
                        GotFocus="UIElement_OnGotFocus">
                <Rectangle Width="15" Height="15" Fill="{Binding Path=Brush}" />
                <TextBlock Text="{Binding Path=Category}"/>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

0 个答案:

没有答案
相关问题