开发者

Silverlight ListBox custom keyboard selection behavior

I am customizing a templated multi-selection-enabled ListBox and can't easily implement the following feature - if there is only one item selected which is also current (focused), when user navigates up or down the list the selection should follow current item. I tried to subscribe to GotFocus event of the DataTemplate's StackPanel, but apparently I don't receive those events (even though MouseEnter/MouseLeave work).

I guess I could do it by modifying a somewhat similar behavior, but isn't there an easier way? This looks like a pretty basic behavior to me...

<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>
开发者_StackOverflow社区
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜