Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

WPF - Fix Width and Height measurement when GetDesiredSize #3750

Merged
merged 4 commits into from
Sep 17, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="UTF-8"?>
<controls:TestContentPage
xmlns:controls="clr-namespace:Xamarin.Forms.Controls"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Controls.Issues"
x:Class="Xamarin.Forms.Controls.Issues.Issue1588">

<StackLayout VerticalOptions="FillAndExpand" >

<ScrollView>
<StackLayout>
<Label Text="General information" FontSize="40" TextColor="#212121" FontFamily="Times New Roman"/>
<local:Divider Thickness="1" Color="#BDBDBD" Margin="0, 20, 0, 0" Orientation="Horizontal"/>
<StackLayout Padding="20">
<StackLayout WidthRequest="300">
<Label Text="NAME" FontAttributes="Bold" TextColor="#212121" Margin="0,0,0,20" />

<local:LabledEntry LabelText="In english" LabelTextColor="#757575" />
</StackLayout>

<StackLayout WidthRequest="300">
<Label Text="CONTACT INFORMATION" FontAttributes="Bold" TextColor="#212121" Margin="0,0,0,20"/>
<local:LabledEntry LabelText="Mobile" LabelTextColor="#757575" />
<local:LabledEntry LabelText="Telephone" LabelTextColor="#757575" />
<local:LabledEntry LabelText="Email" LabelTextColor="#757575" />
<local:LabledEntry LabelText="Website" LabelTextColor="#757575" />
</StackLayout>

<StackLayout WidthRequest="300">
<Label Text="TAX INFORMATION" FontAttributes="Bold" TextColor="#212121" Margin="0,0,0,20"/>
<local:LabledEntry LabelText="Tax card" LabelTextColor="#757575" />
<local:LabledEntry LabelText="Tax file no." LabelTextColor="#757575" />
<local:LabledEntry LabelText="Commerial regestration" LabelTextColor="#757575" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Commerial regestration" -> "Commercial Registration"

</StackLayout>
</StackLayout>


</StackLayout>

</ScrollView>
<StackLayout Orientation="Horizontal" VerticalOptions="End" >
<Button Text="Save" TextColor="White"/>
</StackLayout>
</StackLayout>
</controls:TestContentPage>
Original file line number Diff line number Diff line change
@@ -0,0 +1,349 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;

namespace Xamarin.Forms.Controls.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Github, 1588, "[WPF] Stacklayout WidthRequest adds unwanted margin", PlatformAffected.WPF)]
public partial class Issue1588 : TestContentPage
{
public Issue1588 ()
{
InitializeComponent ();
}

protected override void Init()
{
}
}

public enum EntryOrientation
{
Vertical,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

Horizontal
}

class LabledEntry : ContentView
{
StackLayout stk;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private members should use _ prefix.


Label label;

Entry entry;

public static readonly BindableProperty FontSizeProperty = BindableProperty.Create(
"FontSize",
typeof(double),
typeof(LabledEntry),
Device.GetNamedSize(NamedSize.Small, typeof(Entry)),
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
var fontSize = (double)newvalue;
labledEntry.entry.FontSize = fontSize;
labledEntry.label.FontSize = fontSize;
});

public double FontSize
{
set { SetValue(FontSizeProperty, value); }
get { return (double)GetValue(FontSizeProperty); }
}

public static readonly BindableProperty OrientationProperty = BindableProperty.Create(
"Orientation",
typeof(EntryOrientation),
typeof(LabledEntry),
EntryOrientation.Vertical,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
var orientation = (EntryOrientation)newvalue;
labledEntry.stk.Orientation = orientation == EntryOrientation.Vertical ? StackOrientation.Vertical : StackOrientation.Horizontal;
labledEntry.Orientation = orientation;
});

public EntryOrientation Orientation
{
set { SetValue(OrientationProperty, value); }
get { return (EntryOrientation)GetValue(OrientationProperty); }
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line

public static readonly BindableProperty KeyboardProperty = BindableProperty.Create(
"Keyboard",
typeof(Keyboard),
typeof(LabledEntry),
Keyboard.Default,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
var keyboard = (Keyboard)newvalue;
labledEntry.entry.Keyboard = keyboard;
labledEntry.Keyboard = keyboard;
});

public Keyboard Keyboard
{
set { SetValue(KeyboardProperty, value); }
get { return (Keyboard)GetValue(KeyboardProperty); }
}

public static readonly BindableProperty LabelTextProperty = BindableProperty.Create(
"LabelText",
typeof(string),
typeof(LabledEntry),
null,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
labledEntry.label.Text = (string)newvalue;
labledEntry.LabelText = (string)newvalue;
});

public string LabelText
{
set { SetValue(LabelTextProperty, value); }
get { return (string)GetValue(LabelTextProperty); }
}

public static readonly BindableProperty EntryTextProperty = BindableProperty.Create(
"EntryText",
typeof(string),
typeof(LabledEntry),
null,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
labledEntry.entry.Text = (string)newvalue;
labledEntry.EntryText = (string)newvalue;
});

public string EntryText
{
set { SetValue(EntryTextProperty, value); }
get { return (string)GetValue(EntryTextProperty); }
}

public static readonly BindableProperty PlaceholderProperty = BindableProperty.Create(
"Placeholder",
typeof(string),
typeof(LabledEntry),
null,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
labledEntry.entry.Placeholder = (string)newvalue;
labledEntry.Placeholder = (string)newvalue;
});

public string Placeholder
{
set { SetValue(PlaceholderProperty, value); }
get { return (string)GetValue(PlaceholderProperty); }
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line

public static readonly BindableProperty LabelTextColorProperty = BindableProperty.Create(
"LabelTextColor",
typeof(Color),
typeof(LabledEntry),
Color.Default,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
labledEntry.label.TextColor = (Color)newvalue;
labledEntry.LabelTextColor = (Color)newvalue;
});

public Color LabelTextColor
{
set { SetValue(LabelTextColorProperty, value); }
get { return (Color)GetValue(LabelTextColorProperty); }
}

public static readonly BindableProperty EntryTextColorProperty = BindableProperty.Create(
"EntryTextColor",
typeof(Color),
typeof(LabledEntry),
Color.Default,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
labledEntry.entry.TextColor = (Color)newvalue;
labledEntry.EntryTextColor = (Color)newvalue;
});

public Color EntryTextColor
{
set { SetValue(EntryTextColorProperty, value); }
get { return (Color)GetValue(EntryTextColorProperty); }
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line

public static readonly BindableProperty PlaceholderColorProperty = BindableProperty.Create(
"PlaceholderColor",
typeof(Color),
typeof(LabledEntry),
Color.Default,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);
labledEntry.entry.PlaceholderColor = (Color)newvalue;
labledEntry.PlaceholderColor = (Color)newvalue;
});

public Color PlaceholderColor
{
set { SetValue(PlaceholderColorProperty, value); }
get { return (Color)GetValue(PlaceholderColorProperty); }
}


public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create(
"MaxLength",
typeof(int),
typeof(LabledEntry),
30,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var labledEntry = ((LabledEntry)bindable);

});

public int MaxLength
{
set { SetValue(MaxLengthProperty, value); }
get { return (int)GetValue(MaxLengthProperty); }
}

public LabledEntry()
{
stk = new StackLayout();
entry = new Entry();
entry.FontSize = Device.GetNamedSize(NamedSize.Small, entry);
label = new Label();
entry.FontSize = Device.GetNamedSize(NamedSize.Small, label);
entry.HorizontalOptions = LayoutOptions.FillAndExpand;
label.VerticalOptions = LayoutOptions.Center;
stk.Children.Add(label);
stk.Children.Add(entry);
Content = stk;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra blank line

}
}

public enum DividerOrientation
{
Vertical,

Horizontal
}
class Divider : ContentView
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing blank line

{
BoxView line;

public static readonly BindableProperty OrientationProperty = BindableProperty.Create(
"Orientation",
typeof(DividerOrientation),
typeof(Divider),
DividerOrientation.Vertical,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var divider = ((Divider)bindable);
var orientation = (DividerOrientation)newvalue;
if (orientation == DividerOrientation.Vertical)
{
divider.line.WidthRequest = divider.Thickness;
divider.line.HeightRequest = -1;
}
else
{
divider.line.HeightRequest = divider.Thickness;
divider.line.WidthRequest = -1;
}
divider.Orientation = orientation;
});

public DividerOrientation Orientation
{
set { SetValue(OrientationProperty, value); }
get { return (DividerOrientation)GetValue(OrientationProperty); }
}

public static readonly BindableProperty ColorProperty = BindableProperty.Create(
"Color",
typeof(Color),
typeof(Divider),
Color.Black,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var divider = ((Divider)bindable);
divider.line.Color = (Color)newvalue;
divider.Color = (Color)newvalue;
});

public Color Color
{
set { SetValue(ColorProperty, value); }
get { return (Color)GetValue(ColorProperty); }
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

public static readonly BindableProperty ThicknessProperty = BindableProperty.Create(
"Thickness",
typeof(double),
typeof(Divider),
1.0,
BindingMode.TwoWay,
propertyChanged: (bindable, oldvalue, newvalue) =>
{
var divider = ((Divider)bindable);
var thickness = (double)newvalue;
if (divider.Orientation == DividerOrientation.Vertical)
{
divider.line.WidthRequest = thickness;
}
else
{
divider.line.HeightRequest = thickness;
}
divider.Thickness = thickness;
});

public double Thickness
{
set { SetValue(ThicknessProperty, value); }
get { return (double)GetValue(ThicknessProperty); }
}

public Divider()
{
line = new BoxView();
Content = line;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra line

}
}
}
Loading