Skip to content

Fix VerticalTextAlignment Override not being set when initializing #626

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
24 changes: 21 additions & 3 deletions src/FluentAvalonia/Styling/Core/FluentAvaloniaTheme.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
using Avalonia;
using Avalonia.Collections;
using Avalonia.Controls;
using Avalonia.Controls.Presenters;
using Avalonia.Layout;
using Avalonia.Markup.Xaml;
using Avalonia.Media;
using Avalonia.Platform;
using Avalonia.Styling;
using Avalonia.Threading;
using FluentAvalonia.Interop;
using FluentAvalonia.UI.Media;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -133,8 +136,20 @@ public Color? CustomAccentColor
/// to get a consistent experience, at the (small) expense of breaking Fluent design principles. If your controls
/// never use multi-line text, you'll never see the effect of this property.
/// </remarks>
public TextVerticalAlignmentOverride TextVerticalAlignmentOverrideBehavior { get; set; } =
TextVerticalAlignmentOverride.EnabledNonWindows;
public TextVerticalAlignmentOverride TextVerticalAlignmentOverrideBehavior
{
get => _textAlignmentOverride;
set
{
if (_textAlignmentOverride != value)
{
// NOTE: Attempting to downgrade this after startup will not
// remove the styles - this still requires an app restart
_textAlignmentOverride = value;
SetTextAlignmentOverrides();
}
}
}

public AvaloniaList<IResourceDictionary> MergedDictionaries { get; }

Expand Down Expand Up @@ -393,7 +408,7 @@ private void SetTextAlignmentOverrides()
// may get messed up b/c of the centered alignment
var s3 = new Style(x =>
{
return x.OfType<ComboBox>().Template().OfType<ContentControl>().Child().OfType<TextBlock>();
return x.OfType<ComboBox>().Template().OfType<ContentPresenter>().Child().OfType<TextBlock>();
});
s3.Setters.Add(new Setter(Layoutable.VerticalAlignmentProperty, VerticalAlignment.Center));
Add(s3);
Expand Down Expand Up @@ -555,6 +570,9 @@ private void MergedDictionariesCollectionChanged(object sender, NotifyCollection
private ResourceDictionary _accentColorsDictionary;
private IPlatformSettings _platformSettings;

private TextVerticalAlignmentOverride _textAlignmentOverride =
TextVerticalAlignmentOverride.EnabledNonWindows;

public const string LightModeString = "Light";
public const string DarkModeString = "Dark";
public const string HighContrastModeString = "HighContrast";
Expand Down