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

UiTextBox and ComboBox ignore Width when HorizontalAlignment is set #1318

Open
gleclair opened this issue Jan 15, 2025 · 0 comments
Open

UiTextBox and ComboBox ignore Width when HorizontalAlignment is set #1318

gleclair opened this issue Jan 15, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@gleclair
Copy link

gleclair commented Jan 15, 2025

Describe the bug

For at least two controls I've noticed, if you set the Width property (in XAML), and also set the HorizontalAlignment property, Width will be ignored.

To Reproduce

  1. Create a simple XAML page with a Grid.
  2. Set the Width of the Page or Grid to have excess space (stretch to take up the whole page)
  3. Add a UITextBox or ComboBox control, and set the Width as well as HorizontalAlignment:
    <ui:TextBox Grid.Column="1" Grid.Row="1" Text="SomeText" Width="250" HorizontalAlignment="Left"/>

Run the app and display the page

Expected behavior

Expected: The UiTextBox or ComboBox will be the requested Width and be aligned to the left side of the containing grid.
Actual: The control is aligned to the Left but is much smaller than the set Width.
Note: You can see the problem in design mode as well, in Visual Studio 2022. Remove the HorizontalAlignment property setter and then Width is correct.

Screenshots

No response

OS version

Windows 11

.NET version

.Net 9.0

WPF-UI NuGet version

3.0.5

Additional context

The issue can be resolved by modifying the source's original Style. In the case of a TextBox, the DefaultTextBoxStyle defined in TextBox.xaml:
... <Setter Property="SnapsToDevicePixels" Value="True" /> <Setter Property="OverridesDefaultStyle" Value="True" /> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type TextBox}"> <Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}"> <!--- TO FIX: remove the HorizontalAlignment and VerticalAlignment setters: <Grid> --> <Border x:Name="ContentBorder" MinWidth="{TemplateBinding MinWidth}" ...

@gleclair gleclair added the bug Something isn't working label Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant