示例#1
0
		/// <summary>
		/// Initializes a new instance of the <see cref="WF.Player.DirectionBarPage"/> class.
		/// </summary>
		public DirectionBarPage()
		{
			layout = new StackLayout() 
			{
				BackgroundColor = Color.Transparent,
				Orientation = StackOrientation.Horizontal,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
				Spacing = 4,
				IsClippedToBounds = false,
			};

			var layoutButtons = new StackLayout() 
			{
				BackgroundColor = Color.Transparent,
				Orientation = StackOrientation.Horizontal,
				HorizontalOptions = LayoutOptions.FillAndExpand,
				VerticalOptions = LayoutOptions.FillAndExpand,
			};

			layout.Children.Add(layoutButtons);

			// Placeholder for the DirectionArrow
			placeholder = new BoxView() 
			{
				Color = Color.Transparent,
				WidthRequest = DirectionSize,
			};

			layout.Children.Add(placeholder);

			// Add the new layout to the old one
			BottomLayout.Children.Add(layout);

			// Now replace the old bottom layout with a new one
			BottomLayout = layoutButtons;

			var relativeLayout = (RelativeLayout)ContentLayout.Parent;

			layoutDirection = new StackLayout() 
			{
				Padding = 0,
			};

			direction = new DirectionArrow() 
			{
				BackgroundColor = Color.Transparent, // This is mandatory for Android. If not, direction isn't drawn.
				CircleColor = App.Colors.DirectionBackground,
				ArrowColor = App.Colors.DirectionColor,
				HeightRequest = DirectionSize,
				WidthRequest = DirectionSize,
				HorizontalOptions = LayoutOptions.End,
			};

			distance = new Label() 
			{
				BackgroundColor = Color.Transparent,
				TextColor = App.Colors.Text,
				Text = string.Empty,
				HorizontalOptions = LayoutOptions.Center,
			};

			layoutDirection.Children.Add(direction);
			layoutDirection.Children.Add(distance);

			relativeLayout.Children.Add(
				layoutDirection,
				Constraint.RelativeToParent((parent) => parent.Width - DirectionSize - 4),
				Constraint.RelativeToParent((parent) => parent.Height - layoutDirection.Height - 4));

			// Do this, because Xamarin.Forms don't update the relative layout after calculationg the size of the direction stack.
			layoutDirection.PropertyChanged += (object sender, System.ComponentModel.PropertyChangedEventArgs e) => {
				if(e.PropertyName == "Height")
				{
					relativeLayout.ForceLayout();
				}
			};

		}
示例#2
0
		/// <summary>
		/// Initializes a new instance of the <see cref="WF.Player.GameMainCellView"/> class.
		/// </summary>
		public GameMainCellView()
		{
			this.horiLayout = new StackLayout() 
				{
					BackgroundColor = Color.Transparent,
					Orientation = StackOrientation.Horizontal,
					Spacing = 5,
					Padding = new Thickness(10, 0, 0, 0),
					VerticalOptions = LayoutOptions.FillAndExpand,
					HorizontalOptions = LayoutOptions.FillAndExpand,
				};

			this.icon = new Image() 
			{
				BackgroundColor = Color.Transparent,
				WidthRequest = 48,
				HeightRequest = 48,
				Aspect = Aspect.AspectFit,
			};
			this.icon.SetBinding(Image.SourceProperty, GameMainCellViewModel.IconSourcePropertyName);
			this.icon.SetBinding(Image.IsVisibleProperty, GameMainCellViewModel.ShowIconPropertyName);

			var iconFrame = new Frame() 
				{
					WidthRequest = 1,
					HasShadow = false,
					Padding = new Thickness(0, 5),
				};

			iconFrame.SetBinding(Frame.HeightRequestProperty, GameMainCellViewModel.MinimumRowHeightPropertyName);

			this.name = new Label() 
				{
					XAlign = TextAlignment.Start,
					VerticalOptions = LayoutOptions.Center,
					HorizontalOptions = LayoutOptions.StartAndExpand,
					MinimumHeightRequest = 50,
					FontSize = Settings.FontSize,
					FontFamily = Settings.FontFamily,
					TextColor = App.Colors.Text,
				};
			this.name.SetBinding(Label.TextProperty, GameMainCellViewModel.NamePropertyName);

			var vertLayout = new StackLayout() 
			{
				WidthRequest = 54,
				Orientation = StackOrientation.Vertical,
				Spacing = 5,
				Padding = new Thickness(10, 5),
				VerticalOptions = LayoutOptions.End, //FillAndExpand,
				HorizontalOptions = LayoutOptions.End,
			};
			vertLayout.SetBinding(StackLayout.IsVisibleProperty, GameMainCellViewModel.ShowDirectionPropertyName);

			var direction = new DirectionArrow() 
			{
				BackgroundColor = Color.Transparent,
				CircleColor = App.Colors.DirectionBackground,
				ArrowColor = App.Colors.DirectionColor,
				WidthRequest = 32,
				HeightRequest = 32,
				HorizontalOptions = LayoutOptions.End,
			};
			direction.SetBinding(DirectionArrow.DirectionProperty, GameMainCellViewModel.DirectionPropertyName);

			var distance = new Label() 
			{
				TextColor = App.Colors.Text,
				Font = Font.SystemFontOfSize(12),
				XAlign = TextAlignment.Center,
				HorizontalOptions = LayoutOptions.End,
			};
			distance.SetBinding(Label.TextProperty, GameMainCellViewModel.DistancePropertyName, BindingMode.OneWay, new ConverterToDistance());

			vertLayout.Children.Add(direction);
			vertLayout.Children.Add(distance);

			this.horiLayout.Children.Add(this.icon);
			this.horiLayout.Children.Add(iconFrame);
			this.horiLayout.Children.Add(this.name);
			this.horiLayout.Children.Add(vertLayout);

			View = this.horiLayout;
		}