tags:

views:

24

answers:

2

Hello.

In my window I have the listview and other elements. How I can achieve such behavior of focus: when I press downkey on last listitem focus moves from listview on another element, accordingly pressing upkey on first element moves focus away from list. So focus on pressing up-downkeys can move from other elements to the list, pass throw the list and leave from the list.

Thanks in advance.

A: 

Set the KeyboardNavigation.DirectionalNavigation attached property to Continue. The default for ListBox is Contained.

<ListBox KeyboardNavigation.DirectionalNavigation="Continue"/>
Quartermeister
Thanks, but it just makes listitems circling. How to force keyboardfocus to pass to other element by pressing up-down keys ?
Void
@Void: Setting it to Cycle would do that, but Continue should let it leave. Do you have the ListBox nested inside another control that may have it set to Cycle? The ListBox may be letting focus leave, and then the parent control is setting it back to the start of the ListBox again. It may help if you post some of your XAML.
Quartermeister
ok. I've posted some of xaml.
Void
A: 

I have different situations in my application. For all controls I have my styles, but in style for the tabcontrol I set property KeyboardNavigation.DirectionalNavigation="Continue". 1. Here should have possibility to be selected listviewitems and tabitems. And when focus on tabitem and I press (->) tabitem changes. 2. Here should have possibility to be selected listboxitems and buttons. 3. Here should have possibility to be selected TabItem and TextBlocks. And I can use just arrows not tab. 1:

<TabControl  Name="tabControl1">
        <TabItem Header="PORT" Name="PORT">             
                <ListView  x:Name="ATList"                              
                          ItemsSource="{Binding Path=., NotifyOnTargetUpdated=true}"  
                          KeyboardNavigation.DirectionalNavigation="Continue"
                          KeyUp="ATList_KeyUp"  TargetUpdated="ATList_TargetUpdated">                        
                    <ListView.View>
                        <GridView >
                            <GridViewColumn> ........
                            </GridViewColumn>
                        </GridView>
                    </ListView.View>
                </ListView>               
        </TabItem>
        .......
</TabControl>    

2.

<Grid> 
    <ListBox ItemsSource="{Binding    NotifyOnSourceUpdated=True,  NotifyOnTargetUpdated=True}"
             KeyboardNavigation.DirectionalNavigation="Continue"
             ClipToBounds="true" TargetUpdated="List_TargetUpdated" SourceUpdated="List_SourceUpdated">          
    </ListBox>
    <WrapPanel>  
        <Label  .../>
        <Label  .../>              
        <Button x:Name="NewBtn"                     
                IsEnabled="{Binding ElementName=UsedMemory, Path = Content, Converter={StaticResource RouteNewConverter}}" 
                Click="NewRouteBtn_Click"> New </Button>            
        <Button x:Name="DeleteBtn"  Click="DeleteBtn_Click"> Delete </Button>
    </WrapPanel>
</Grid>

3.

 <TabControl Margin="2,5,2,1" Name="tabControl1" >
        <TabItem Header="AV" Name="AV">
            <Grid>
                <StackPanel x:Name="inf">
                            <TextBlock />
                                    ...
                            <TextBlock />                                            
                </StackPanel> 
            </Grid>
        </TabItem>
</TabControl>
Void