Пример #1
0
		public MainWindow ()
		{
			WidthRequest = 997;
			HeightRequest = 679;
			Title = "fkalc";

			var fileMenuItem = new MenuItem ()
			{
				Header = new TextBlock()
				{
					Text = "File"
				},
				ItemsSource = new ObservableCollection<UIElement>()
				{ 
					new TextBlock() { Text = "New", HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(20, 0, 50, 5) },
					new TextBlock() { Text = "Open", HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(20, 0, 50, 5)}, 
					new TextBlock() { Text = "Close", HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(20, 0, 50, 5)}
				},
				//Template = new ControlTemplate(MenuItemTemplate),
				Margin = new Thickness(5),
			};

			var menuItems = new ObservableCollection<MenuItem> () { fileMenuItem };

			var menu = new Menu ()
			{
				HorizontalAlignment = HorizontalAlignment.Stretch,
				VerticalAlignment = VerticalAlignment.Stretch,
				ItemsSource = menuItems,
			};

			var document = new DocumentView ()
			{
				DataContext = new DocumentViewModel ()
			};

			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 ());

			grid.Children.Add (menu);
			grid.Children.Add (document);		

			grid.SetRow (0, menu);
			grid.SetColumn (0, menu);

			grid.SetRow (1, document);
			grid.SetColumn (0, document);

			Content = grid;
		}
Пример #2
0
		private UIElement DocumentTemplate (object o)
		{
			var viewModel = o as DependencyObject;

			var document = new DocumentView ()
			{
				DataContext = viewModel,
			};

			var header = new TextBlock ();
			BindingOperations.SetBinding (viewModel.GetProperty ("Title"), header.GetProperty ("Text")); 

			return new TabItem () { Header = header, Content = document };
		}