Is there a way to put a border in its contents? (Winnrt Xaml)

I have a border around the text block to create a nice background with rounded corners. But no matter what I do, the width of the border is always equal to the size of its parent. I want to limit it to the size of my content. I tried snapping the width to the actual width of its contents, but this did not work with any snapping mode.

<Border x:Name="TagPreviewBorder" CornerRadius="5"
        Width="{Binding ElementName=TagPreviewTextBlock, Path=ActualWidth, Mode=TwoWay}">
   <TextBlock x:Name="TagPreviewTextBlock"/>
</Border>
+5
source share
1 answer

An easy desktop would be to forget Borderin your xaml and use TextBoxinstead TextBlockas follows:

<TextBox Text="Your Text Here" 
         IsReadOnly="True" Background="Transparent" BorderBrush="Red" 
         BorderThickness="3" HorizontalAlignment="Left"/>

UPDATE: I checked again and it looks like you forgot to set BorderHorizontalAlignment

This also works:

    <Border CornerRadius="5" HorizontalAlignment="Left" BorderThickness="10">
        <TextBlock Text="My Text Here"></TextBlock>
    </Border>
+6
source

All Articles