question

zipswich avatar image
0 Votes"
zipswich asked ·

How to prevent AppBarButton.Label from wrapping?

Is there a way to prevent AppBarButton.Label from wrapping?


windows-uwpwindows-uwp-xaml
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RichardZhang-MSFT avatar image
1 Vote"
RichardZhang-MSFT answered ·

Hello,​

Welcome to our Microsoft Q&A platform!

Did you mean that the label no longer wraps automatically when the Label is at the bottom of the AppBarButton?

This is the default behavior of AppBarButton and does not provide an external API to change this behavior. If you want to implement this requirement, you need to modify the style of AppBarButton

Try this code:

Due to forum reasons, XAML code cannot be posted for the time being, we are actively addressing this issue

Xaml Code

Imgur

The key modification is this TextBlock. In the default style, its TextWrapping property is Wrap. Here we can modify it.

At the same time, in order to remind the user that the Label is not displayed completely, we can set TextTrimming = "CharacterEllipsis" so that an ellipsis will be displayed when the text overflows.


Usage

<AppBarButton Label="Test Button" Style="{StaticResource AppBarButtonNoWrapStyle}"/>

Thanks



xaml.txt (22.3 KiB)
· 4 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks a lot. The style works very well.

0 Votes 0 ·

@RichardZhangWicresoftNorthAmericaL-8157
I have noticed that UseSystemFocusVisuals causes the following exception on Windows 10 Build 16299.

 Exception: The text associated with this error code could not be found.
    
 Cannot find a Resource with the Name/Key UseSystemFocusVisuals [Line: 0 Position: 0]
 Type: Windows.UI.Xaml.Markup.XamlParseException
 Stack trace:    at System.Runtime.InteropServices.McgMarshal.ThrowOnExternalCallFailed(Int32, RuntimeTypeHandle) + 0x21
    at __Interop.ComCallHelpers.Call(__ComObject, RuntimeTypeHandle, Int32, Type__Impl.UnsafeType, Void*, Void*) + 0xd5
    at Windows.UI.Xaml.Controls.IFrame__Impl.Stubs.Navigate(__ComObject, Type, Object) + 0x8e



Is this expected?

0 Votes 0 ·

With the update of the system version, the style of controls in UWP will also change. UseSystemFocusVisuals should be a property added in the new system, if you want to support the old version, you can delete UseSystemFocusVisuals.

1 Vote 1 ·
Show more comments