我輸出的東西類似於Windows 8的開始菜單。將MoveFocus從一個列表框移動到另一個列表框
這裏是我的輸出的屏幕截圖:
我已經成功地得到了輸出由this問題得到幫助。
XAML實現以下的輸出:
<ItemsControl ItemsSource="{Binding MenuCategories}" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel IsItemsHost="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBlock Text="{Binding Title}" FontSize="30" />
<ListBox Grid.Row="1" x:Name="lst" ItemsSource="{Binding Design_Master_TileItem}" BorderThickness="0"
SelectedItem="{Binding DataContext.SelectedTile, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type Page}}}"
helpers:SingleSelectionGroup.SelectionGroup="Group">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Vertical" MaxHeight="{Binding ElementName=lst, Path=ActualHeight}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.Resources>
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="Width" Value="250" />
<Setter Property="Height" Value="125" />
<Setter Property="Margin" Value="2.5" />
<Setter Property="Padding" Value="2.5" />
<Setter Property="Background" Value="{Binding Background, Converter={StaticResource stringToBrushConverter}}" />
<Setter Property="Foreground" Value="White" />
<Setter Property="VerticalContentAlignment" Value="Bottom" />
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Foreground" Value="{Binding Background, Converter ={StaticResource stringToBrushConverter}}" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Setter Property="IsSelected" Value="True"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="125" Width="250">
<Path Data="{Binding ImageData}" VerticalAlignment="Center"
Stretch="Uniform" Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"
Width="68" Height="68" Margin="10" RenderTransformOrigin="0.5,0.5">
<Path.RenderTransform>
<TransformGroup>
<TransformGroup.Children>
<RotateTransform Angle="0" />
<ScaleTransform ScaleX="1" ScaleY="1" />
</TransformGroup.Children>
</TransformGroup>
</Path.RenderTransform>
</Path>
<TextBlock Text="{Binding Title, Converter={StaticResource spaceToNewLineConverter}}" VerticalAlignment="Top"
Margin="40,10,10,10" FontSize="24" Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type ListBoxItem}}}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
所以,從上面的代碼中你可能已經明白,集團和總帳是ListBox1中的兩個項目。其他四個是listbox2的項目。
要求:
假設,ItemA1在listboxA選擇。
案例1:新行爲
如果ListBoxA不會對項目1右側的任何項目,然後當我按下右箭頭鍵重點應轉移到listboxB的ItemB1。同樣,如果選擇listboxA的ItemA2,則焦點應移至ListBoxB的ItemB2。
案例2:默認行爲
如果ListBoxA對ItemA1的右手邊的一些項目,則該項目應該按右箭頭鍵選擇。我默認有這種行爲,但我不想打擾它。我的意思是在實施Case1時,我不想失去默認行爲。
不幸的是,我不能說完全是,但嘗試這種風格添加到'ListBox':'<樣式的TargetType = 「{x:類型列表框}」><觸發屬性=」 HasItems「Value =」False「>'。這意味着如果'ListBox'中沒有元素,他不能接收焦點。 –
不,你完全錯誤地理解了我的問題。 ListBox的ItemsPanel被設置爲WrapPanel,方向=垂直。現在閱讀有關的要求部分。我想你現在會知道我想要什麼。 – Vishal
對不起,沒有再次理解這個問題,但我提前警告說,我不能肯定地說。我認爲這很難做到,因爲你在DataTemplate中有一個'ListBox',並且正在訪問多個'ListBox'。是的,這可以通過一個龐大而醜陋的代碼和算法來完成,這個算法應該考慮到每一方的元素。因此,如果你有另一種選擇,我建議找她。如果沒有,我會接受這個挑戰,我不能確切地說它什麼時候會完成。然而,如果你想讓我開始完成這個任務,請給我一個鏈接到你的項目。 –