// Demonstrates using system colors to fill rectangles and buttons. private void listSystemBrushes() { // The window style (defined in Window1.xaml) is used to // specify the height and width of each of the System.Windows.Shapes.Rectangles. System.Windows.Controls.TextBlock t = new System.Windows.Controls.TextBlock(); t.Text = "ActiveBorder"; System.Windows.Shapes.Rectangle r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ActiveBorderBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ActiveCaption"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ActiveCaptionBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ActiveCaptionText"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ActiveCaptionTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "AppWorkspace"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.AppWorkspaceBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "Control"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ControlBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ControlDark"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ControlDarkBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ControlDarkDark"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ControlDarkDarkBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ControlLight"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ControlLightBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ControlLightLight"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ControlLightLightBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ControlText"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ControlTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "Desktop"; r = new System.Windows.Shapes.Rectangle(); //r.Fill = SystemColors.DesktopBrush; r.SetResourceReference(System.Windows.Shapes.Shape.FillProperty, System.Windows.SystemColors.DesktopBrushKey); systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "GradientActiveCaption"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.GradientActiveCaptionBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "GradientInactiveCaption"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.GradientInactiveCaptionBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "GrayText"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.GrayTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "Highlight"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.HighlightBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "HighlightText"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.HighlightTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "HotTrack"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.HotTrackBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "InactiveBorder"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.InactiveBorderBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "InactiveCaption"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.InactiveCaptionBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "InactiveCaptionText"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.InactiveCaptionTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "Info"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.InfoBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "InfoText"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.InfoTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "Menu"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.MenuBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "MenuBar"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.MenuBarBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "MenuHighlight"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.MenuHighlightBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "MenuText"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.MenuTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "ScrollBar"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.ScrollBarBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new System.Windows.Controls.TextBlock(); t.Text = "Window"; r = new System.Windows.Shapes.Rectangle(); r.Fill = SystemColors.WindowBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); // Try it out on a button. t = new System.Windows.Controls.TextBlock(); t.Text = "WindowFrame"; System.Windows.Controls.Button b = new System.Windows.Controls.Button(); b.Width = 120; b.Height = 20; b.Background = SystemColors.WindowFrameBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(b); t = new System.Windows.Controls.TextBlock(); t.Text = "WindowText"; b = new System.Windows.Controls.Button(); b.Width = 120; b.Height = 20; b.Background = SystemColors.WindowTextBrush; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(b); }
//在画布上显示一个矩形 private void ShowRectanglesInCanvas(Rectangle rect, int i,int j) { rect.Width = rectWidth; rect.Height = rectHeight; rect.Fill = new SolidColorBrush(Colors.LightBlue); rect.SetValue(Canvas.TopProperty, (double)((i+1) * rectsTopSpace));//j rect.SetValue(Canvas.LeftProperty, (double)((j+1) * rectsLeftSpace));//i //后台设置style rect.SetResourceReference(Rectangle.StyleProperty, "myRectangle"); MainWindow.owner.canvas.Children.Add(rect); }
// Demonstrates using system colors to fill rectangles and buttons. private void ListSystemBrushes() { // The window style (defined in Window1.xaml) is used to // specify the height and width of each of the System.Windows.Shapes.Rectangles. var t = new TextBlock {Text = "ActiveBorder"}; var r = new Rectangle { Fill = SystemColors.ActiveBorderBrush }; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ActiveCaption"}; r = new Rectangle {Fill = SystemColors.ActiveCaptionBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ActiveCaptionText"}; r = new Rectangle {Fill = SystemColors.ActiveCaptionTextBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "AppWorkspace"}; r = new Rectangle {Fill = SystemColors.AppWorkspaceBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "Control"}; r = new Rectangle {Fill = SystemColors.ControlBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ControlDark"}; r = new Rectangle {Fill = SystemColors.ControlDarkBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ControlDarkDark"}; r = new Rectangle {Fill = SystemColors.ControlDarkDarkBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ControlLight"}; r = new Rectangle {Fill = SystemColors.ControlLightBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ControlLightLight"}; r = new Rectangle {Fill = SystemColors.ControlLightLightBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ControlText"}; r = new Rectangle {Fill = SystemColors.ControlTextBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "Desktop"}; r = new Rectangle(); //r.Fill = SystemColors.DesktopBrush; r.SetResourceReference(Shape.FillProperty, SystemColors.DesktopBrushKey); systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "GradientActiveCaption"}; r = new Rectangle {Fill = SystemColors.GradientActiveCaptionBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "GradientInactiveCaption"}; r = new Rectangle {Fill = SystemColors.GradientInactiveCaptionBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "GrayText"}; r = new Rectangle {Fill = SystemColors.GrayTextBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "Highlight"}; r = new Rectangle {Fill = SystemColors.HighlightBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "HighlightText"}; r = new Rectangle {Fill = SystemColors.HighlightTextBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "HotTrack"}; r = new Rectangle {Fill = SystemColors.HotTrackBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "InactiveBorder"}; r = new Rectangle {Fill = SystemColors.InactiveBorderBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "InactiveCaption"}; r = new Rectangle {Fill = SystemColors.InactiveCaptionBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "InactiveCaptionText"}; r = new Rectangle {Fill = SystemColors.InactiveCaptionTextBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "Info"}; r = new Rectangle {Fill = SystemColors.InfoBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "InfoText"}; r = new Rectangle {Fill = SystemColors.InfoTextBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "Menu"}; r = new Rectangle {Fill = SystemColors.MenuBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "MenuBar"}; r = new Rectangle {Fill = SystemColors.MenuBarBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "MenuHighlight"}; r = new Rectangle {Fill = SystemColors.MenuHighlightBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "MenuText"}; r = new Rectangle {Fill = SystemColors.MenuTextBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "ScrollBar"}; r = new Rectangle {Fill = SystemColors.ScrollBarBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); t = new TextBlock {Text = "Window"}; r = new Rectangle {Fill = SystemColors.WindowBrush}; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(r); // Try it out on a button. t = new TextBlock {Text = "WindowFrame"}; var b = new Button { Width = 120, Height = 20, Background = SystemColors.WindowFrameBrush }; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(b); t = new TextBlock {Text = "WindowText"}; b = new Button { Width = 120, Height = 20, Background = SystemColors.WindowTextBrush }; systemBrushesPanel.Children.Add(t); systemBrushesPanel.Children.Add(b); }
/// <summary> /// This method is invoked when a view is opened /// </summary> /// <param name="context">Request context (contains information about the view)</param> /// <returns> /// True if handled successfully /// </returns> public bool OpenView(RequestContext context) { if (context.Result is StatusMessageResult) return HandleStatusMessage(context); if (context.Result is NotificationMessageResult) { var result = context.Result as NotificationMessageResult; return HandleNotificationMessage(context, result.Model.OverrideTimeout); } var viewResult = context.Result as ViewResult; if (viewResult != null && viewResult.ForceNewShell) if ((viewResult.ViewLevel == ViewLevel.Normal && NormalViewCount > 0) || (viewResult.ViewLevel == ViewLevel.TopLevel && TopLevelViewCount > 0)) { // A new shell should be opened, so we try to create another shell and then hand off view opening duties to it, rather than handling it directly var shellLauncher = Controller.GetShellLauncher() as WindowShellLauncher<Shell>; if (shellLauncher != null) if (shellLauncher.OpenAnotherShellInstance()) return Current.OpenView(context); } var messageBoxResult = context.Result as MessageBoxResult; if (messageBoxResult != null) { if (messageBoxResult.View == null) { var messageBoxViewModel = messageBoxResult.Model as MessageBoxViewModel; if (messageBoxViewModel != null) { var textBlock = new TextBlock {TextWrapping = TextWrapping.Wrap, Text = messageBoxViewModel.Text}; textBlock.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-MessageBox-Text"); if (!string.IsNullOrEmpty(messageBoxViewModel.IconResourceKey)) { var grid = new Grid(); grid.ColumnDefinitions.Clear(); grid.ColumnDefinitions.Add(new ColumnDefinition {Width = GridLength.Auto}); grid.ColumnDefinitions.Add(new ColumnDefinition {Width = new GridLength(1, GridUnitType.Star)}); var rect = new Rectangle {Fill = messageBoxViewModel.IconBrush}; rect.SetResourceReference(StyleProperty, "CODE.Framework.Wpf.Mvvm.Shell-MessageBox-Image"); grid.Children.Add(rect); grid.Children.Add(textBlock); Grid.SetColumn(textBlock, 1); SimpleView.SetSizeStrategy(grid, ViewSizeStrategies.UseMinimumSizeRequired); messageBoxResult.View = grid; } else messageBoxResult.View = textBlock; } } if (messageBoxResult.View != null) { var messageBoxModelAction = messageBoxResult.Model as IHaveActions; if (messageBoxModelAction != null) { messageBoxResult.View.InputBindings.Clear(); foreach (var action in messageBoxModelAction.Actions) if (action.ShortcutKey != Key.None) messageBoxResult.View.InputBindings.Add(new KeyBinding(action, action.ShortcutKey, action.ShortcutModifiers)); } } } if (viewResult != null && viewResult.View != null && !viewResult.IsPartial) { if (viewResult.ViewLevel == ViewLevel.Popup || viewResult.ViewLevel == ViewLevel.StandAlone || viewResult.ViewLevel == ViewLevel.TopLevel) return OpenTopLevelView(context, messageBoxResult, viewResult); // This is an normal (main) view // Need to make sure we do not open more than allowed if (MaximumNormalViewCount > -1) { var inplaceNormalViews = NormalViews.Where(v => v.TopLevelWindow == null).ToList(); while (inplaceNormalViews.Count + 1 > MaximumNormalViewCount) { CloseViewForModel(inplaceNormalViews[0].Model); inplaceNormalViews.RemoveAt(0); } } NormalViews.Add(viewResult); if (viewResult.MakeViewVisibleOnLaunch) { FocusManager.SetFocusedElement(this, viewResult.View); SelectedNormalView = NormalViews.Count - 1; SelectedNormalViewResult = SelectedNormalView > -1 ? NormalViews[SelectedNormalView] : null; } NormalViewCount = NormalViews.Count; if (NormalViewLaunchMode == ViewLaunchMode.Popup) OpenNormalViewInWindow(context, viewResult); return true; } return false; }