Last active
August 29, 2015 13:56
-
-
Save JohanLarsson/9217262 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System.Linq; | |
| using System.Windows.Input; | |
| using FirstFloor.ModernUI.Windows.Controls; | |
| public static class ModernCommands | |
| { | |
| static ModernCommands() | |
| { | |
| var nextBinding = new CommandBinding(ModernCommands.NextTab, ExecuteNextTab, CanExecuteNextTab); | |
| CommandManager.RegisterClassCommandBinding(typeof(ModernTab), nextBinding); | |
| var prevBinnding = new CommandBinding(ModernCommands.PreviousTab, ExecutePreviousTab, CanExecutePreviousTab); | |
| CommandManager.RegisterClassCommandBinding(typeof(ModernTab), prevBinnding); | |
| } | |
| private static readonly RoutedCommand Next = new RoutedCommand("NextTab", typeof(ModernCommands)); | |
| private static readonly RoutedCommand Previous = new RoutedCommand("PreviousTab", typeof(ModernCommands)); | |
| public static RoutedCommand NextTab | |
| { | |
| get | |
| { | |
| return Next; | |
| } | |
| } | |
| public static RoutedCommand PreviousTab | |
| { | |
| get | |
| { | |
| return Previous; | |
| } | |
| } | |
| private static void CanExecuteNextTab(object sender, CanExecuteRoutedEventArgs e) | |
| { | |
| var tab = sender as ModernTab; | |
| if (tab == null || tab.SelectedSource == null) | |
| { | |
| e.CanExecute = false; | |
| return; | |
| } | |
| e.CanExecute = IsInRange(CurrentIndex(tab) + 1, tab); | |
| } | |
| private static void ExecuteNextTab(object sender, ExecutedRoutedEventArgs e) | |
| { | |
| var tab = (ModernTab)sender; | |
| tab.SelectedSource = tab.Links[CurrentIndex(tab) + 1].Source; | |
| } | |
| private static void CanExecutePreviousTab(object sender, CanExecuteRoutedEventArgs e) | |
| { | |
| var tab = sender as ModernTab; | |
| if (tab == null || tab.SelectedSource == null) | |
| { | |
| e.CanExecute = false; | |
| return; | |
| } | |
| e.CanExecute = IsInRange(CurrentIndex(tab) - 1, tab); | |
| } | |
| private static void ExecutePreviousTab(object sender, ExecutedRoutedEventArgs e) | |
| { | |
| var tab = (ModernTab)sender; | |
| tab.SelectedSource = tab.Links[CurrentIndex(tab) - 1].Source; | |
| } | |
| private static int CurrentIndex(ModernTab tab) | |
| { | |
| return tab.Links.IndexOf(tab.Links.FirstOrDefault(x => x.Source == tab.SelectedSource)); | |
| } | |
| private static bool IsInRange(int i, ModernTab tab) | |
| { | |
| return i < tab.Links.Count && i > -1; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <Grid> | |
| <Grid.RowDefinitions> | |
| <RowDefinition Height="*"/> | |
| <RowDefinition Height="Auto"/> | |
| </Grid.RowDefinitions> | |
| <mui:ModernTab Layout="Tab" x:Name="Tab"> | |
| <mui:ModernTab.Links> | |
| <mui:Link DisplayName="Language" Source="/View1.xaml" /> | |
| <mui:Link DisplayName="Item 2" Source="/View2.xaml" /> | |
| </mui:ModernTab.Links> | |
| </mui:ModernTab> | |
| <StackPanel Grid.Row="1" Orientation="Horizontal"> | |
| <Button Content="Previous" | |
| Command="commands:ModernCommands.PreviousTab" | |
| CommandTarget="{Binding ElementName=Tab}"/> | |
| <Button Content="Next" | |
| Command="commands:ModernCommands.NextTab" | |
| CommandTarget="{Binding ElementName=Tab}"/> | |
| </StackPanel> | |
| </Grid> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment