Ejemplo n.º 1
0
        private bool SetNavMenu()
        {
            List <MenuItem> output = new();

            Type type = typeof(Terminal);

            PropertyInfo[] terminalProps = type.GetProperties()
                                           .Where(p => p.PropertyType.GetInterfaces().Contains(typeof(INavegable)))
                                           .ToArray();

            int i = 0;

            foreach (PropertyInfo p in terminalProps)
            {
                LandingPageAttribute landingPage = (LandingPageAttribute)p.GetCustomAttributes(typeof(LandingPageAttribute)).FirstOrDefault();
                if (landingPage.IsEnabled)
                {
                    ButtonSettingsAttribute buttonSetting = (ButtonSettingsAttribute)p.GetCustomAttributes(typeof(ButtonSettingsAttribute)).FirstOrDefault();

                    MenuItem item = new(i, landingPage.Display, landingPage.IsSelected);
                    item.SetContet($"Views/{landingPage.Page}.xaml");

                    item.TextColor = new SolidColorBrush(buttonSetting.TextColor);

                    byte[]   bgcColorChannels = buttonSetting.BackgroundColor.ToChannelsBytes();
                    HSBColor middleColor      = HSBColor.FromARGB(bgcColorChannels);
                    middleColor.Desaturate(56);

                    item.BackgroundColor = new LinearGradientBrush(
                        new GradientStopCollection(new List <GradientStop>
                    {
                        new GradientStop(buttonSetting.BackgroundColor, 0.5),
                        new GradientStop(middleColor.ToARGB().ToMediaColor(), 0.75),
                        new GradientStop(buttonSetting.BackgroundColor, 1)
                    }),
                        new Point(0, 0),
                        new Point(0, 1)
                        );

                    output.Add(item);
                    i++;
                }
            }

            output.Reverse();
            NavDestinations = output.ToObservableCollection();

            if (NavDestinations.Count > 0)
            {
                Destination = NavDestinations.FirstOrDefault(m => m.DefaultSelected);
                if (Destination == null)
                {
                    Destination = NavDestinations[0];
                }
            }

            if (Destination != null)
            {
                return(true);
            }

            return(false);
        }