Beispiel #1
0
        public override object OnConvert(object value, Type targetType, object parameter, string language)
        {
            var text = value as string;

            if (string.IsNullOrEmpty(text))
            {
                return(string.Empty);
            }

            if (text.Contains("<Inline>") && text.Contains("</Inline>"))
            {
                // We can have multiple inlined localized texts in the string... We have to remove
                // them all
                text = "<Inline>" + text.Replace("<Inline>", "").Replace("</Inline>", "") + "</Inline>";

                var textBlock = new TextBlock();
                textBlock.Inlines.Clear();
                textBlock.Inlines.Add(XAMLHelper.ParseToInline(text));
                textBlock.VerticalAlignment   = VerticalAlignment.Stretch;
                textBlock.HorizontalAlignment = HorizontalAlignment.Stretch;
                textBlock.TextWrapping        = TextWrapping.Wrap;
                textBlock.TextTrimming        = TextTrimming.None;
                textBlock.TextAlignment       = TextAlignment.Justify;
                textBlock.MaxWidth            = 350;

                return(textBlock);
            }

            return(text);
        }
        private void DeleteEntryButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Object context = XAMLHelper.GetDataContext <Object>(sender as DependencyObject);
            Entry  entry   = context.GetField <Entry>("Source");

            DeleteEntryStream.OnNext(entry);
        }
Beispiel #3
0
        private void SetValidationInfo(BindingExpression bindingExpression)
        {
            if (bindingExpression == null)
            {
                return;
            }

            // get the binding sources in order to do some voodoo on them
            var source = bindingExpression.ParentBinding.Source as INotifyDataErrorInfo;

            if (source == null)
            {
                source = this.AssociatedObject.DataContext as INotifyDataErrorInfo;
            }

            // we don't support too complicated binding paths
            var propertyName = bindingExpression.ParentBinding.Path.Path;

            // check if the property name end with a ']' ... We dont support that
            if (propertyName.Right(1) == "]")
            {
                return;
            }

            if (propertyName.Contains('.'))
            {
                source       = XAMLHelper.GetSourceFromPath(source, propertyName) as INotifyDataErrorInfo;
                propertyName = propertyName.Right(propertyName.Length - propertyName.LastIndexOf('.') - 1);
            }

            // if our source is still null then either the source does not implements the
            // INotifyDataErrorInfo interface or we dont have a valid source at all In both cases we
            // just give up
            if (source == null)
            {
                return;
            }

            // then let us check if the binding source have validation attributes on them
            var property = source.GetType().GetPropertyEx(propertyName);

            if (property == null)
            {
                return;
            }

            if (!this.validableProperties.ContainsKey(propertyName) && property.GetCustomAttributes().Any(x => x is ValidatorAttributeBase))
            {
                this.validableProperties.Add(propertyName, new WeakReference <INotifyDataErrorInfo>(source));
                source.ErrorsChanged += this.Source_ErrorsChanged;
                (source as IValidatableViewModel).IsNotNull(x => x.Validating += Source_Validating);

                // Also... If we have a mandatory attribute... Add it
                if (property.GetCustomAttribute <IsMandatoryAttribute>() != null)
                {
                    ValidationProperties.SetIsMandatory(this.AssociatedObject, true);
                }
            }
        }
 private static void SourceOnMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     DragSource = DragSourceFinder.GetDragSource(e.OriginalSource, XAMLHelper.GetDataTemplate((DependencyObject)e.OriginalSource));
     if (DragSource != null)
     {
         e.Handled = true;
     }
 }
        internal static DragSourceInfo GetDragSource(object frameworkElement, DataTemplate template)
        {
            if (frameworkElement is FrameworkElement element && element.DataContext is IDragSource item)
            {
                var root = XAMLHelper.FindParent <LayoutDesignerControl>(element);
                return(new DragSourceInfo(item, new AdornerContent(root, item, template), root));
            }

            return(null);
        }
Beispiel #6
0
 public void ConfigureWindowBlur()
 {
     if (SettingsService.Get <bool>(SettingsKeys.IsAcrylicBlurEnabled) && ApiInformationHelper.IsCreatorsUpdateOrLater && !ApiInformationHelper.IsMobileDevice)
     {
         BlurBorder.Background = XAMLHelper.GetResourceValue <CustomAcrylicBrush>("HostBackdropAcrylicBrush");
     }
     else
     {
         BlurBorder.Background = (Brush)XAMLHelper.GetGenericResourceValue("ApplicationPageBackgroundThemeBrush");
     }
 }
Beispiel #7
0
 public async Task ConfigureHamburgerMenuBlur()
 {
     if (ApiInformationHelper.IsCreatorsUpdateOrLater)
     {
         BlurBorderHamburger.Background = XAMLHelper.GetResourceValue <CustomAcrylicBrush>("InAppAcrylicBrush");
     }
     else
     {
         await BlurBorderHamburger.AttachCompositionBlurEffect(20, 100, true);
     }
 }
        public MainWindow()
        {
            InitializeComponent();
            radar           = new Radar();
            radar.RadarGrid = grid;
            radar.ActualMap = new Map("Immobiles.txt");

            foreach (Immobile immobile in radar.ActualMap.Immobiles)
            {
                radar.RadarGrid.Children.Add(XAMLHelper.CreateImageFromImmobile(immobile));
            }
        }
Beispiel #9
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            // Set the right theme-depending color for the alternating rows
            if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
            {
                XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush", new SolidColorBrush {
                    Color = Color.FromArgb(0x08, 0, 0, 0)
                });
            }

            CustomFrame rootFrame = Window.Current.Content as CustomFrame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new CustomFrame();

                rootFrame.NavigationFailed += OnNavigationFailed;
            }

            if (!e.PrelaunchActivated)
            {
                if (rootFrame.Content == null)
                {
                    Window.Current.Content = new MainPage();
                }

                if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
                {
                    var view = ApplicationView.GetForCurrentView();
                    view.SetPreferredMinSize(new Size(width: 800, height: 600));

                    var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                    if (titleBar != null)
                    {
                        titleBar.BackgroundColor = titleBar.ButtonBackgroundColor = (Color)App.Current.Resources["SystemAltHighColor"];
                    }
                }

                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
Beispiel #10
0
 public async Task ConfigureHamburgerMenuBlur()
 {
     if (ApiInformationHelper.IsCreatorsUpdateOrLater)
     {
         if (!ApiInformationHelper.IsMobileDevice && HamSplitView.DisplayMode == SplitViewDisplayMode.Inline)
         {
             BlurBorderHamburger.Background = XAMLHelper.GetResourceValue <CustomAcrylicBrush>("HamburgerBackdropAcrylicBrush");
         }
         else
         {
             BlurBorderHamburger.Background = XAMLHelper.GetResourceValue <CustomAcrylicBrush>("InAppAcrylicBrush");
         }
     }
     else
     {
         await BlurBorderHamburger.AttachCompositionBlurEffect(20, 100, true);
     }
 }
Beispiel #11
0
        protected async override void OnActivated(IActivatedEventArgs args)
        {
            if (args.Kind == ActivationKind.Protocol)
            {
                if (args.PreviousExecutionState == ApplicationExecutionState.Running)
                {
                    await HandleProtocolActivationArguments(args);
                }
                else
                {
                    if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
                    {
                        XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush", new SolidColorBrush {
                            Color = Color.FromArgb(0x08, 0, 0, 0)
                        });
                    }

                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }

                    if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
                    {
                        var view = ApplicationView.GetForCurrentView();
                        view.SetPreferredMinSize(new Size(width: 800, height: 600));

                        var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                        if (titleBar != null)
                        {
                            titleBar.BackgroundColor                           =
                                titleBar.ButtonBackgroundColor                 =
                                    titleBar.InactiveBackgroundColor           =
                                        titleBar.ButtonInactiveBackgroundColor =
                                            (Color)App.Current.Resources["SystemChromeLowColor"];

                            titleBar.ForegroundColor = (Color)App.Current.Resources["SystemChromeHighColor"];
                        }
                    }
                    Window.Current.Activate();
                }
            }
        }
Beispiel #12
0
        private static void OnToolTipChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            if (XAMLHelper.GetIsInDesignMode(dependencyObject))
            {
                return;
            }

            var value            = args.NewValue as string;
            var text             = string.IsNullOrEmpty(value) ? string.Empty : Locale.Current[value];
            var frameworkElement = dependencyObject as FrameworkElement;

            if (frameworkElement == null)
            {
                return;
            }

            if (text.StartsWith("<Inline>") && text.EndsWith("</Inline>"))
            {
                var textBlock = new TextBlock();
                textBlock.Inlines.Clear();
                textBlock.Inlines.Add(XAMLHelper.ParseToInline(text));
                textBlock.VerticalAlignment   = VerticalAlignment.Stretch;
                textBlock.HorizontalAlignment = HorizontalAlignment.Stretch;
                textBlock.TextWrapping        = TextWrapping.Wrap;
                textBlock.TextTrimming        = TextTrimming.None;
                textBlock.TextAlignment       = TextAlignment.Justify;
                textBlock.MaxWidth            = 350;

#if WINDOWS_UWP
                ToolTipService.SetToolTip(frameworkElement, textBlock);
#else
                frameworkElement.ToolTip = textBlock;
#endif
            }
            else

#if WINDOWS_UWP
            { ToolTipService.SetToolTip(frameworkElement, text); }
#else
            { frameworkElement.ToolTip = text; }
#endif
        }
        private void AddEntryButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Template context = XAMLHelper.GetDataContext <Template>(sender as DependencyObject);

            if (context != null)
            {
                AddEntryStream.OnNext(new Entry
                {
                    Description = context.Description,
                    Points      = context.Points,
                });
            }
            else
            {
                AddEntryStream.OnNext(new Entry
                {
                    Description = NewEntryDescription.Text,
                    Points      = int.Parse(NewEntryPoints.Text),
                });
            }
        }
Beispiel #14
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override void OnLaunched(LaunchActivatedEventArgs e)
        {
            // Set the right theme-depending color for the alternating rows
            if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
            {
                XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush", new SolidColorBrush {
                    Color = Color.FromArgb(0x08, 0, 0, 0)
                });
            }

            if (!e.PrelaunchActivated)
            {
                if (Window.Current.Content == null)
                {
                    Window.Current.Content = new MainPage(null);
                    (Window.Current.Content as Page).OpenFromSplashScreen(e.SplashScreen.ImageLocation);
                }

                if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
                {
                    var view = ApplicationView.GetForCurrentView();
                    view.SetPreferredMinSize(new Size(width: 800, height: 600));

                    var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                    if (titleBar != null)
                    {
                        titleBar.BackgroundColor                           =
                            titleBar.ButtonBackgroundColor                 =
                                titleBar.InactiveBackgroundColor           =
                                    titleBar.ButtonInactiveBackgroundColor =
                                        (Color)App.Current.Resources["SystemChromeLowColor"];

                        titleBar.ForegroundColor = (Color)App.Current.Resources["SystemChromeHighColor"];
                    }
                }

                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
Beispiel #15
0
        private void MainPage_SizeChanged(object sender, SizeChangedEventArgs e)
        {
            if (Window.Current.Bounds.Width < 1024)
            {
                ViewModel.DisplayMode = SplitViewDisplayMode.Overlay;
                ViewModel.IsPaneOpen  = false;

                if (ApiInformationHelper.IsCreatorsUpdateOrLater)
                {
                    BlurBorderHamburger.Background = XAMLHelper.GetResourceValue <CustomAcrylicBrush>("InAppAcrylicBrush");
                }
            }
            else
            {
                ViewModel.DisplayMode = SplitViewDisplayMode.Inline;
                ViewModel.IsPaneOpen  = true;

                if (ApiInformationHelper.IsCreatorsUpdateOrLater && !ApiInformationHelper.IsMobileDevice)
                {
                    BlurBorderHamburger.Background = XAMLHelper.GetResourceValue <CustomAcrylicBrush>("HamburgerBackdropAcrylicBrush");
                }
            }
        }
        private void DeleteTemplateButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Template context = XAMLHelper.GetDataContext <Template>(sender);

            DeleteTemplateStream.OnNext(context);
        }
        private void DeleteBountyButton_Tapped(object sender, TappedRoutedEventArgs e)
        {
            Bounty context = XAMLHelper.GetDataContext <Bounty>(sender);

            DeleteBountyStream.OnNext(context);
        }
Beispiel #18
0
        private static void OnTextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            var newValue = args.NewValue as string;

            var text = string.IsNullOrEmpty(newValue) ?
                       string.Empty :
                       (newValue.StartsWith("<Inline>") && newValue.EndsWith("</Inline>") ? newValue : Locale.Current[newValue]);

            if (dependencyObject is TextBlock)
            {
                var textBlock = dependencyObject as TextBlock;

                if (text.StartsWith("<Inline>") && text.EndsWith("</Inline>"))
                {
                    textBlock.Inlines.Clear();
                    textBlock.Inlines.Add(XAMLHelper.ParseToInline(text));
                }
                else
                {
                    textBlock.Text = text;
                }
            }
#if WINDOWS_UWP
            else if (dependencyObject is TextBox)
            {
                var element = dependencyObject as TextBox;
                element.Header = text;
            }
            else if (dependencyObject is ComboBox)
            {
                var element = dependencyObject as ComboBox;
                element.Header = text;
            }
            else if (dependencyObject is ButtonBase)
            {
                (dependencyObject as ButtonBase).Content = text;
            }
#else
            else if (dependencyObject is HeaderedContentControl)
            {
                (dependencyObject as HeaderedContentControl).Header = text;
            }
            else if (dependencyObject is HeaderedItemsControl)
            {
                (dependencyObject as HeaderedItemsControl).Header = text;
            }
            else if (dependencyObject is GridViewColumn)
            {
                (dependencyObject as GridViewColumn).Header = text;
            }
#endif
            else if (dependencyObject is ContentControl)
            {
                (dependencyObject as ContentControl).Content = text;
            }
            else
            {
                // We just try to get a title property - this will not work in UWP Native
                var title = dependencyObject.GetType().GetProperty("Title", BindingFlags.Public | BindingFlags.Instance);
                if (title != null)
                {
                    title.SetValue(dependencyObject, text);
                }
            }
        }
Beispiel #19
0
        private async void OnLaunchedOrActivated(IActivatedEventArgs args)
        {
            // Set the right theme-depending color for the alternating rows
            if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
            {
                XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush", new SolidColorBrush {
                    Color = Color.FromArgb(0x08, 0, 0, 0)
                });
            }
            if (args is LaunchActivatedEventArgs launchArgs)
            {
                if (!launchArgs.PrelaunchActivated)
                {
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(null);
                        (Window.Current.Content as Page).OpenFromSplashScreen(launchArgs.SplashScreen.ImageLocation);
                    }
                }
                Activate();
                Window.Current.Activate();
                BackgroundTaskService.RegisterAppTriggerBackgroundTasks();
            }
            else if (args is ToastNotificationActivatedEventArgs toastActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.Protocol)
                {
                    if (args.PreviousExecutionState == ApplicationExecutionState.Running)
                    {
                        await HandleProtocolActivationArguments(args);
                    }
                    else
                    {
                        if (Window.Current.Content == null)
                        {
                            Window.Current.Content = new MainPage(args);
                        }
                        Activate();
                    }
                }
                else if (args.Kind == ActivationKind.ToastNotification)
                {
                    var mainPageType = typeof(FeedView);
                    var backPageType = typeof(NotificationsView);
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    else
                    {
                        var svc = SimpleIoc
                                  .Default
                                  .GetInstance <IAsyncNavigationService>();
                        try
                        {
                            var toastArgs      = QueryString.Parse(toastActivatedEventArgs.Argument);
                            var notificationId = toastArgs["notificationId"] as string;
                            var repoId         = long.Parse(toastArgs["repoId"]);

                            string group = null,
                                   tag   = $"N{notificationId}+R{repoId}";

                            var repo = await RepositoryUtility.GetRepository(repoId);

                            switch (toastArgs["action"])
                            {
                            case "showIssue":
                                var issueNumber = int.Parse(toastArgs["issueNumber"]);

                                var issue = await IssueUtility.GetIssue(repo.Id, issueNumber);

                                tag  += $"+I{issueNumber}";
                                group = "Issues";
                                await svc.NavigateAsync(typeof(IssueDetailView), new Tuple <Repository, Issue>(repo, issue), backPageType : backPageType);

                                break;

                            case "showPr":
                                var prNumber = int.Parse(toastArgs["prNumber"]);
                                var pr       = await PullRequestUtility.GetPullRequest(repoId, prNumber);

                                tag  += $"+P{pr.Number}";
                                group = "PullRequests";
                                await svc.NavigateAsync(typeof(PullRequestDetailView), new Tuple <Repository, PullRequest>(repo, pr), backPageType : backPageType);

                                break;
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(tag) && !StringHelper.IsNullOrEmptyOrWhiteSpace(group))
                            {
                                ToastNotificationManager.History.Remove(tag, group);
                            }
                            if (!StringHelper.IsNullOrEmptyOrWhiteSpace(notificationId))
                            {
                                await NotificationsService.MarkNotificationAsRead(notificationId);
                            }
                        }
                        catch
                        {
                            await svc.NavigateAsync(mainPageType);
                        }
                    }

                    Activate();
                    Window.Current.Activate();
                }
            }
            else if (args is StartupTaskActivatedEventArgs startupTaskActivatedEventArgs)
            {
                if (args.Kind == ActivationKind.StartupTask)
                {
                    var payload = ActivationKind.StartupTask.ToString();
                    if (Window.Current.Content == null)
                    {
                        Window.Current.Content = new MainPage(args);
                    }
                    (Window.Current.Content as Frame).Navigate(typeof(NotificationsView));
                }
            }
        }
Beispiel #20
0
        /// <summary>
        /// Invoked when the application is launched normally by the end user.  Other entry points
        /// will be used such as when the application is launched to open a specific file.
        /// </summary>
        /// <param name="e">Details about the launch request and process.</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs e)
        {
            // Set the right theme-depending color for the alternating rows
            if (SettingsService.Get <bool>(SettingsKeys.AppLightThemeEnabled))
            {
                XAMLHelper.AssignValueToXAMLResource("OddAlternatingRowsBrush",
                                                     new SolidColorBrush {
                    Color = Color.FromArgb(0x08, 0, 0, 0)
                });
            }

            CustomFrame rootFrame = Window.Current.Content as CustomFrame;

            // Do not repeat app initialization when the Window already has content,
            // just ensure that the window is active
            if (rootFrame == null)
            {
                // Create a Frame to act as the navigation context and navigate to the first page
                rootFrame = new CustomFrame();

                rootFrame.NavigationFailed += OnNavigationFailed;

                if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    //TODO: Load state from previously suspended application
                }

                // Place the frame in the current Window
                Window.Current.Content = rootFrame;
            }

            if (e.PrelaunchActivated == false)
            {
                if (rootFrame.Content == null)
                {
                    // When the navigation stack isn't restored navigate to the first page,
                    // configuring the new page by passing a boolean as navigation parameter,
                    // indicating whether the user is logged in or not

                    if (await AuthService.checkAuth())
                    {
                        await rootFrame.Navigate(typeof(MainPage), true);
                    }
                    else
                    {
                        await rootFrame.Navigate(typeof(MainPage), false);
                    }
                }

                if (ApiInformation.IsTypePresent("Windows.UI.ViewManagement.ApplicationView"))
                {
                    var view = ApplicationView.GetForCurrentView();
                    view.SetPreferredMinSize(new Size(width: 800, height: 600));

                    var titleBar = ApplicationView.GetForCurrentView().TitleBar;
                    if (titleBar != null)
                    {
                        titleBar.BackgroundColor = titleBar.ButtonBackgroundColor = (Color)App.Current.Resources["SystemAltHighColor"];
                    }
                }

                // Ensure the current window is active
                Window.Current.Activate();
            }
        }
Beispiel #21
0
        private static void OnTextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args)
        {
            if (XAMLHelper.GetIsInDesignMode(dependencyObject))
            {
                return;
            }

            var newValue = args.NewValue as string;

            var text = string.IsNullOrEmpty(newValue) ?
                       string.Empty :
                       (newValue.StartsWith("<Inline>") && newValue.EndsWith("</Inline>") ? newValue : Locale.Current[newValue]);

            if (dependencyObject is TextBlock)
            {
                var textBlock = dependencyObject as TextBlock;

                if (text.StartsWith("<Inline>") && text.EndsWith("</Inline>"))
                {
                    textBlock.Inlines.Clear();
                    textBlock.Inlines.Add(XAMLHelper.ParseToInline(text));
                }
                else
                {
                    textBlock.Text = text;
                }
            }
#if WINDOWS_UWP
            else if (dependencyObject is TextBox)
            {
                var element = dependencyObject as TextBox;
                element.Header = text;
            }
            else if (dependencyObject is ComboBox)
            {
                var element = dependencyObject as ComboBox;
                element.Header = text;
            }
            else if (dependencyObject is ButtonBase)
            {
                (dependencyObject as ButtonBase).Content = text;
            }
#else
            else if (dependencyObject is HeaderedContentControl)
            {
                (dependencyObject as HeaderedContentControl).Header = text;
            }
            else if (dependencyObject is HeaderedItemsControl)
            {
                (dependencyObject as HeaderedItemsControl).Header = text;
            }
            else if (dependencyObject is GridViewColumn)
            {
                (dependencyObject as GridViewColumn).Header = text;
            }
#endif
            else if (dependencyObject is ContentControl)
            {
                (dependencyObject as ContentControl).Content = text;
            }

            Localized.SetLocalizedText(dependencyObject, text);
        }