Reputation: 1142
I have a NavigationView
in my app. I want to add counters/badges to some of the items. But whatever I do, the badge always stays right next to the label. See the image below (on the top is what I have, on the bottom what I want to achieve)
The code I'm currently using is the following:
<NavigationViewItem Icon="Mail">
<NavigationViewItem.Content>
<RelativePanel HorizontalAlignment="Stretch">
<TextBlock RelativePanel.AlignLeftWithPanel="True">Inbox</TextBlock>
<local:Badge RelativePanel.AlignRightWithPanel="True" BadgeText="30"/> <!-- can be replaced with a simple "TextBlock" -->
</RelativePanel>
</NavigationViewItem.Content>
</NavigationViewItem>
(You can subsitute the Badge
control with a simple TextBlock
)
Upvotes: 0
Views: 254
Reputation: 32775
The problem is that RelativePanel
can't get SplitViewOpenPaneThemeLength
automatically. so we need specific the width for RelativePanel
. As we known SplitViewOpenPaneThemeLength
is 320, and SplitViewCompactPaneThemeLength
is 48. so the
width of NavigationViewItem.Content
is 320-48 = 272. Please refer the following xaml code.
<RelativePanel HorizontalAlignment="Stretch" Width="{ThemeResource SplitViewOpenPaneThemeLength}">
<TextBlock RelativePanel.AlignLeftWithPanel="True">Inbox</TextBlock>
<TextBlock RelativePanel.AlignRightWithPanel="True" Text="30" Margin="0,0,48,0"/>
<!-- can be replaced with a simple "TextBlock" -->
</RelativePanel>
Upvotes: 1