Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement HorizontalTextAlignment property in WinUI Picker #947

Merged
merged 4 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions eng/package.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ param(
[string] $msbuild = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe"
)

$ErrorActionPreference = "Stop"

$artifacts = Join-Path $PSScriptRoot ../artifacts
$sln = Join-Path $PSScriptRoot ../Microsoft.Maui-net6.sln

Expand Down Expand Up @@ -58,13 +60,15 @@ if ($IsWindows)
/t:build `
/p:Packing=true `
/bl:"$artifacts/maui-build-$configuration.binlog"
if (!$?) { throw "Build failed." }

& $msbuild $sln `
/p:configuration=$configuration `
/p:SymbolPackageFormat=snupkg `
/t:pack `
/p:Packing=true `
/bl:"$artifacts/maui-pack-$configuration.binlog"
if (!$?) { throw "Build failed." }
}
finally
{
Expand All @@ -86,4 +90,5 @@ else
-c:$configuration `
-p:SymbolPackageFormat=snupkg `
-bl:$artifacts/maui-pack-$configuration.binlog
if (!$?) { throw "Build failed." }
}
1 change: 1 addition & 0 deletions src/Compatibility/Core/src/WinUI/AlignmentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ internal static VerticalAlignment ToNativeVerticalAlignment(this TextAlignment a
}
}

[PortHandler]
internal static HorizontalAlignment ToNativeHorizontalAlignment(this TextAlignment alignment)
{
switch (alignment)
Expand Down
2 changes: 2 additions & 0 deletions src/Compatibility/Core/src/WinUI/PickerRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,12 @@ void UpdateTitle()
Control.DataContext = Element;
}

[PortHandler]
void UpdateHorizontalTextAlignment()
{
Control.HorizontalContentAlignment = Element.HorizontalTextAlignment.ToNativeHorizontalAlignment();
}

void UpdateVerticalTextAlignment()
{
Control.VerticalContentAlignment = Element.VerticalTextAlignment.ToNativeVerticalAlignment();
Expand Down
6 changes: 4 additions & 2 deletions src/Core/src/Handlers/Picker/PickerHandler.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ public static void MapTextColor(PickerHandler handler, IPicker picker)
handler.NativeView?.UpdateTextColor(picker, handler._defaultForeground);
}

[MissingMapper]
public static void MapHorizontalTextAlignment(PickerHandler handler, IPicker view) { }
public static void MapHorizontalTextAlignment(PickerHandler handler, IPicker picker)
{
handler.NativeView?.UpdateHorizontalTextAlignment(picker);
}

void OnControlSelectionChanged(object? sender, WSelectionChangedEventArgs e)
{
Expand Down
20 changes: 20 additions & 0 deletions src/Core/src/Platform/Windows/AlignmentExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Microsoft.UI.Xaml;

namespace Microsoft.Maui
{
public static class AlignmentExtensions
{
public static HorizontalAlignment ToNativeHorizontalAlignment(this TextAlignment alignment)
{
switch (alignment)
{
case TextAlignment.Center:
return HorizontalAlignment.Center;
case TextAlignment.End:
return HorizontalAlignment.Right;
default:
return HorizontalAlignment.Left;
}
}
}
}
8 changes: 6 additions & 2 deletions src/Core/src/Platform/Windows/PickerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#nullable enable
using Microsoft.Maui.Graphics;
using Microsoft.UI.Xaml.Controls;
using WBrush = Microsoft.UI.Xaml.Media.Brush;

namespace Microsoft.Maui
Expand Down Expand Up @@ -41,6 +40,11 @@ public static void UpdateCharacterSpacing(this MauiComboBox nativeComboBox, IPic
}

public static void UpdateFont(this MauiComboBox nativeComboBox, IPicker picker, IFontManager fontManager) =>
nativeComboBox.UpdateFont(picker.Font, fontManager);
nativeComboBox.UpdateFont(picker.Font, fontManager);

public static void UpdateHorizontalTextAlignment(this MauiComboBox nativeComboBox, IPicker picker)
{
nativeComboBox.HorizontalContentAlignment = picker.HorizontalTextAlignment.ToNativeHorizontalAlignment();
}
}
}