Пример #1
0
        public ViewModelBase()
        {
            CommandContext = new CommandContext();
            if (Util.IsDesignMode) return;

            metadata = RuntimeContext.Service.GetObject<IMetadataDescriptor>().GetMetadata(GetType());
            RuntimeContext.Service.L10N.PropertyChanged += (s, e) => { RefreshTitle(); };
            //初始化視圖狀態
            ViewStatus.StatusText = RuntimeContext.Service.L10N.GetText("Status.Ready");
            CommandContext.Init(this);
            Initialize();
            RefreshTitle();
        }
Пример #2
0
 List<InputBinding> Load(CommandContext ctx)
 {
     var result = new List<InputBinding>();
     foreach (var cmd in ctx.Commands.OfType<RelayCommandModel>()
         .Where(p => (p.Usage & CommandUsage.KeyBinding) == CommandUsage.KeyBinding))
     {
         foreach (InputGesture g in cmd.InputGestures)
         {
             InputBinding binding = new InputBinding((System.Windows.Input.ICommand)cmd, g);
             result.Add(binding);
         }
     }
     return result;
 }
 List<object> Load(CommandContext ctx)
 {
     var result = new List<object>();
     foreach (var cmd in ctx.Commands.OfType<RelayCommandModel>()
         .Where(p => (p.Usage & CommandUsage.ContextMenu) == CommandUsage.ContextMenu && p.Target.CIEquals(Target))
         .OrderBy(p => p.VisibleIndex))
     {
         if (result.Count > 0 && cmd.BeginGroup)
             result.Add(new Separator());//BeginGroup為True時,加入Separator
         var item = new MenuItem();
         item.Header = RuntimeContext.Service.L10N.GetText("Cmd." + cmd.Name);
         item.Command = (System.Windows.Input.ICommand)cmd;
         result.Add(item);
     }
     return result;
 }
 List<object> Load(CommandContext ctx)
 {
     var result = new List<object>();
     foreach (var model in ctx.Commands.OfType<RelayCommandModel>()
         .Where(p => (p.Usage & CommandUsage.ToolBar) == CommandUsage.ToolBar)
         .OrderBy(p => p.VisibleIndex))
     {
         if (result.Count > 0 && model.BeginGroup)
             result.Add("-");//BeginGroup為True時,增加分割符號,配合SeparatorTemplateSelector生成Separator
         var cmd = new RelayCommandModel();
         cmd.Icon = model.Icon;
         cmd.Command = model.Command;
         RuntimeContext.Service.L10N.PropertyChanged += (s, e) =>
         {
             cmd.Text = RuntimeContext.Service.L10N.GetText("Cmd." + model.Name);
             cmd.ToolTip = RuntimeContext.Service.L10N.GetText("Cmd.ToolTip." + model.Name);
         };
         cmd.Text = RuntimeContext.Service.L10N.GetText("Cmd." + model.Name);
         cmd.ToolTip = RuntimeContext.Service.L10N.GetText("Cmd.ToolTip." + model.Name);
         result.Add(cmd);
     }
     return result;
 }