开发者

Silverlight ListBox custom keyboard selection behavior

开发者 https://www.devze.com 2023-03-23 08:14 出处:网络
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

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

精彩评论

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