-
Notifications
You must be signed in to change notification settings - Fork 708
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
TextBox ignores HorizontalContent/TextAlignment APIs #2896
Comments
Can you try working around this by setting TextAlignment rather than HorizontalTextAlignment on the TextBox? |
@MikeHillberg Not sure how I missed that property 😑 I also checked the documentation and it states:
Edit: I misread the documentation leading me to close this issue. This is an error: The issue is real. |
No, I think it's still a bug; you should be able to use either property, your sample code looks valid. I'm confused by the documentation too. It's saying that this is last-writer-wins behavior, but we have a pretty strict rule to not rely on the order that properties are set (too much ambiguity and too little control). I don't remember how TextBox ended up with this duplicate property, but I think it was anticipating a VerticalTextAlignment property like Xamarin Forms has. |
@MikeHillberg Yep, the documentation confused me for a second here which made me think this is a non-issue. Turns out there really still is an issue here. I wrote some test XAML to check when the <StackPanel Orientation="Horizontal" Margin="0,20,0,20" HorizontalAlignment="Center">
<Button Content="Set HorizontalTextAlignment" Click="Button_Click" Margin="0,0,10,0"/>
<Button Content="Set TextAlignment" Click="Button_Click_1"/>
</StackPanel>
<Border BorderThickness="1" BorderBrush="Black" Margin="0,20,0,20" Grid.Row="3" HorizontalAlignment="Center">
<TextBlock Text="TextBlock text" HorizontalTextAlignment="Right" Width="150" />
</Border>
<TextBox x:Name="DemoTextBox"
Text="TextBox text" Width="150" Grid.Row="4" Margin="0,0,0,20" TextAlignment="Left" HorizontalTextAlignment="Left"/> private void Button_Click(object sender, RoutedEventArgs e)
{
this.DemoTextBox.HorizontalTextAlignment = TextAlignment.Right;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
this.DemoTextBox.TextAlignment = TextAlignment.Right;
} As you can see, setting This doesn't match the documentation for the
There is clearly a disconnect between the documentation and the API behavior (I ran the example code above targeting the 18362 SDK). As it stands now, the A similar issue happens in the case of the TextBlock as well. The documentation has the same remarks and we also see the API behavior vs documentation mismatch: <StackPanel Orientation="Horizontal" Margin="0,20,0,20" HorizontalAlignment="Center">
<Button Content="Set HorizontalTextAlignment" Click="Button_Click" Margin="0,0,10,0"/>
<Button Content="Set TextAlignment" Click="Button_Click_1"/>
</StackPanel>
<Border BorderThickness="1" BorderBrush="Black" Margin="0,20,0,20" Grid.Row="3" HorizontalAlignment="Center">
<TextBlock x:Name="DemoTextBlock" Text="TextBlock text" Width="150" HorizontalTextAlignment="Left" TextAlignment="Left"/>
</Border> private void Button_Click(object sender, RoutedEventArgs e)
{
this.DemoTextBlock.HorizontalTextAlignment = TextAlignment.Right;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
this.DemoTextBlock.TextAlignment = TextAlignment.Right;
} |
@chrisglein or @MikeHillberg do we need to take a follow up to change the documentation in the mean time? |
I'd like to understand first what the details are. |
Hello guys. Do you have plans to fix it or improve the API? I guess this should be better - there are 3 properties but only the TextAlignment works <TextBox HorizontalContentAlignment="Center" HorizontalTextAlignment="Center" TextAlignment="Center"/> |
This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 5 days. |
Issue still valid using WASDK v1.5.5. May the moderators reopen this issue? |
HorizontalContentAlignment is a by product of deriving from Control, but I'm not sure if we need to have both TextAlignment and HorizontalTextAlignment. I think one of these should be removed, but this will be a breaking ABI change. |
Describe the bug
The TextBox control currently ignores the following two APIs to align its text inside of it:
See the following XAML markup:
And the result:
![image](https://user-images.githubusercontent.com/1398851/87349935-6a08a700-c557-11ea-86d5-f275002c5e9f.png)
Expected behavior
Text of the TextBox should also be aligned to the right.
Additional context
![image](https://user-images.githubusercontent.com/1398851/87350363-0a5ecb80-c558-11ea-8ac7-95e5fdb698c3.png)
This bug also affects all the controls using a TextBox internally, such as AutoSuggestBox and NumberBox. This is a gap in WinUI in regards to Win32 APIs like WinForms NumericUpDown control which can align its content to the right just fine:
For the NumberBox, an own issue exists in #1722 which would easily be done once this bug has been fixed.
Version Info
The text was updated successfully, but these errors were encountered: