Пример #1
0
		public static void Main (string[] args)
		{
			Window window = new Window();
			window.Title = "Hello, world";
			window.WidthRequest = 400;
			window.HeightRequest = 300;
			Application.Current.Run (window);
		}
		public void Run (Window window)
		{
			MainWindow = window;
			MainWindow.Closed += (sender, e) => aplication.Shutdown ();
			
			window.Show ();
			
			aplication.Run ();			
		}
		public void RegisterWindow (Window window)
		{
			var width = window.WidthRequest ?? 100;
			var height = window.HeightRequest ?? 50;

			var surface = new GtkSurface (window, window.Left, window.Top, width, height, Gtk.WindowType.Toplevel);
			window.Showed += (sender, e) => surface.ShowSurface ();
			window.Closed += (sender, e) => surface.CloseSurface ();

			window.GetProperty ("Left").DependencyPropertyValueChanged += (sender, e) => surface.Move ((int)window.Left, (int)window.Top);
			window.GetProperty ("Top").DependencyPropertyValueChanged += (sender, e) => surface.Move ((int)window.Left, (int)window.Top);
		}
		public void UnregisterWindow (Window window)
		{
		}	
		private static UIElement WindowTemplate (Window element)
		{
			var grid = new Grid () {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch};
			grid.RowDefinitions.Add (new RowDefinition () {Height = GridLength.Auto});
			grid.RowDefinitions.Add (new RowDefinition ());			
			grid.ColumnDefinitions.Add (new ColumnDefinition ());
			
			var titleGrid = new Grid () {HorizontalAlignment = HorizontalAlignment.Stretch, VerticalAlignment = VerticalAlignment.Stretch};
			titleGrid.RowDefinitions.Add (new RowDefinition ());
			titleGrid.ColumnDefinitions.Add (new ColumnDefinition ());
			titleGrid.ColumnDefinitions.Add (new ColumnDefinition () { Width = GridLength.Auto });
			
			var title = new TextBlock ();		
			title.Foreground = Colors.White;
			title.HorizontalAlignment = HorizontalAlignment.Center;
			BindingOperations.SetBinding (element.GetProperty ("Title"), title.GetProperty ("Text"));
			
			var closeButton = CloseButton ();			
			closeButton.Click += (sender, e) => element.Close ();
			
			titleGrid.Children.Add (title);			
			titleGrid.Children.Add (closeButton);
			
			titleGrid.SetColumn (0, title);
			titleGrid.SetColumn (1, closeButton);
			
			var titleThumb = new Thumb () 
			{
				HorizontalAlignment = HorizontalAlignment.Stretch, 
				VerticalAlignment = VerticalAlignment.Stretch,
				Template = new ControlTemplate(t => titleGrid)
			};
			
			titleThumb.DragDelta += (sender, e) => 
			{
				element.Left += e.HorizontalChange;
				element.Top += e.VerticalChange;
			};
			
			var titleBorder = new Border ();
			titleBorder.Background = GetTitleBrush ();
			titleBorder.Child = titleThumb;
			titleBorder.Padding = new Thickness (3);
			
			grid.Children.Add (titleBorder);
			grid.SetRow (0, titleBorder);
			
			var border = new Border ();
			
			BindingOperations.SetBinding (element.GetProperty ("Padding"), border.GetProperty ("Padding"));
			BindingOperations.SetBinding (element.GetProperty ("Background"), border.GetProperty ("Background"));
			BindingOperations.SetBinding (element.GetProperty ("BorderThickness"), border.GetProperty ("BorderThickness"));
			BindingOperations.SetBinding (element.GetProperty ("BorderColor"), border.GetProperty ("BorderColor"));
			
			BindingOperations.SetBinding (element.GetProperty ("Content"), border.GetProperty ("Child"));
			
			grid.Children.Add (border);
			grid.SetRow (1, border);
			
			return grid;		
		}
		internal void UnregisterWindow (Window window)
		{
			windows.Remove (window);
			aplication.UnregisterWindow (window);
		}
		internal void RegisterWindow (Window window)
		{
			windows.Add (window);
			aplication.RegisterWindow (window);
		}