object Create(ToolBarButtonMD md, IToolBarItemContext ctx, IInputElement commandTarget) { var item = (IToolBarButton)md.ToolBarItem; var md2 = (IToolBarButtonMetadata)md.Metadata; var cmdHolder = item as ICommandHolder; var cmd = cmdHolder != null ? cmdHolder.Command : new RelayCommand(a => item.Execute(ctx), a => item.IsEnabled(ctx)); string header = ResourceHelper.GetString(item, md2.Header); string icon = md2.Icon; string toolTip = ResourceHelper.GetString(item, md2.ToolTip); header = item.GetHeader(ctx) ?? header; toolTip = item.GetToolTip(ctx) ?? toolTip; var imgRef = item.GetIcon(ctx) ?? ImageReferenceHelper.GetImageReference(item, icon) ?? default(ImageReference); var toggleButtonCmd = item as IToolBarToggleButton; Debug.Assert(md2.IsToggleButton == (toggleButtonCmd != null), "Implement IToolBarToggleButton if IsToggleButton is true"); if (toggleButtonCmd != null) { return(CreateToggleButton(toggleButtonCmd.GetBinding(ctx), cmd, commandTarget, header, toolTip, imgRef)); } return(new ToolBarButtonVM(cmd, commandTarget, header, toolTip, imgRef)); }
object Create(ToolBarButtonMD md, IToolBarItemContext ctx, IInputElement commandTarget) { var item = (IToolBarButton)md.ToolBarItem; var md2 = (IToolBarButtonMetadata)md.Metadata; var cmdHolder = item as ICommandHolder; var cmd = cmdHolder != null ? cmdHolder.Command : new RelayCommand(a => item.Execute(ctx), a => item.IsEnabled(ctx)); string header = ResourceHelper.GetString(item, md2.Header); string icon = md2.Icon; string toolTip = ResourceHelper.GetString(item, md2.ToolTip); var item2 = item as IToolBarButton2; if (item2 != null) { header = item2.GetHeader(ctx) ?? header; icon = item2.GetIcon(ctx) ?? icon; toolTip = item2.GetToolTip(ctx) ?? toolTip; } BitmapSource imageSource = null; if (!string.IsNullOrEmpty(icon)) { imageSource = imageManager.GetImage(item.GetType().Assembly, icon, BackgroundType.ToolBar); } var toggleButtonCmd = item as IToolBarToggleButton; Debug.Assert(md2.IsToggleButton == (toggleButtonCmd != null), "Implement IToolBarToggleButton if IsToggleButton is true"); if (toggleButtonCmd != null) { return(CreateToggleButton(toggleButtonCmd.GetBinding(ctx), cmd, commandTarget, header, toolTip, imageSource)); } return(new ToolBarButtonVM(cmd, commandTarget, header, toolTip, imageSource)); }
object Create(ToolBarButtonMD md, IToolBarItemContext ctx, IInputElement commandTarget) { var item = (IToolBarButton)md.ToolBarItem; var md2 = (IToolBarButtonMetadata)md.Metadata; var cmdHolder = item as ICommandHolder; var cmd = cmdHolder != null ? cmdHolder.Command : new RelayCommand(a => item.Execute(ctx), a => item.IsEnabled(ctx)); string header = ResourceHelper.GetString(item, md2.Header); string icon = md2.Icon; string toolTip = ResourceHelper.GetString(item, md2.ToolTip); var item2 = item as IToolBarButton2; if (item2 != null) { header = item2.GetHeader(ctx) ?? header; icon = item2.GetIcon(ctx) ?? icon; toolTip = item2.GetToolTip(ctx) ?? toolTip; } BitmapSource imageSource = null; if (!string.IsNullOrEmpty(icon)) imageSource = imageManager.GetImage(item.GetType().Assembly, icon, BackgroundType.ToolBar); var toggleButtonCmd = item as IToolBarToggleButton; Debug.Assert(md2.IsToggleButton == (toggleButtonCmd != null), "Implement IToolBarToggleButton if IsToggleButton is true"); if (toggleButtonCmd != null) return CreateToggleButton(toggleButtonCmd.GetBinding(ctx), cmd, commandTarget, header, toolTip, imageSource); return new ToolBarButtonVM(cmd, commandTarget, header, toolTip, imageSource); }
object Create(ToolBarButtonMD md, IToolBarItemContext ctx, IInputElement commandTarget) { var item = (IToolBarButton)md.ToolBarItem; var md2 = (IToolBarButtonMetadata)md.Metadata; var cmdHolder = item as ICommandHolder; var cmd = cmdHolder != null ? cmdHolder.Command : new RelayCommand(a => item.Execute(ctx), a => item.IsEnabled(ctx)); string header = ResourceHelper.GetString(item, md2.Header); string icon = md2.Icon; string toolTip = ResourceHelper.GetString(item, md2.ToolTip); header = item.GetHeader(ctx) ?? header; toolTip = item.GetToolTip(ctx) ?? toolTip; var imgRef = item.GetIcon(ctx) ?? ImageReferenceHelper.GetImageReference(item, icon) ?? default(ImageReference); var toggleButtonCmd = item as IToolBarToggleButton; Debug.Assert(md2.IsToggleButton == (toggleButtonCmd != null), "Implement IToolBarToggleButton if IsToggleButton is true"); if (toggleButtonCmd != null) return CreateToggleButton(toggleButtonCmd.GetBinding(ctx), cmd, commandTarget, header, toolTip, imgRef); return new ToolBarButtonVM(cmd, commandTarget, header, toolTip, imgRef); }