Esempio n. 1
0
        public static MenuItem GenerateMenuItem(ContextMenuAttribute attr, MethodInfo mi, object reference)
        {
            MenuItem MI        = new MenuItem();
            bool     Activated = true;
            bool     isMethod  = !bool.TryParse(attr.Activated, out Activated);

            if (isMethod)
            {
                try
                {
                    var mipred = reference.GetType().GetRuntimeMethod(attr.Activated, new Type[] { });
                    var micoll = reference.GetType().GetRuntimeMethods();
                    Activated = (bool)mipred.Invoke(reference, new object[] { });
                }
                catch
                {
                    Activated = false;
                }
            }
            MI.Command = new RelayCommand(o => mi.Invoke(reference, new object[] { }));
            MI.Header  = attr.Header;
            if (!string.IsNullOrEmpty(attr.ImageSource))
            {
                var assets = AvaloniaLocator.Current.GetService <IAssetLoader>();
                MI.Icon = new Image
                {
                    Source = new Bitmap(assets.Open(new Uri("avares://DominoPlanner.Usage/" + attr.ImageSource, UriKind.Absolute)))
                };
            }
            MI.IsVisible = attr.IsVisible;
            MI.IsEnabled = Activated;
            return(MI);
        }
Esempio n. 2
0
        public ContextMenuEntry(ContextMenuAttribute attr, MethodInfo mi, object reference)
        {
            bool Activated = true;
            bool isMethod  = !bool.TryParse(attr.Activated, out Activated);

            if (isMethod)
            {
                try
                {
                    var mipred = reference.GetType().GetRuntimeMethod(attr.Activated, new Type[] { });
                    var micoll = reference.GetType().GetRuntimeMethods();
                    Activated = (bool)mipred.Invoke(reference, new object[] { });
                }
                catch
                {
                    Activated = false;
                }
            }
            Command = new RelayCommand(o => mi.Invoke(reference, new object[] { }));
            Header  = attr.Header;
            if (!string.IsNullOrEmpty(attr.ImageSource))
            {
                Icon = new System.Windows.Controls.Image {
                    Source = new BitmapImage(new Uri(attr.ImageSource, UriKind.Relative))
                }
            }
            ;
            Visibility = attr.Visibility;
            IsEnabled  = Activated;
        }
    }