0

I want to create a textbox with a background of a bubble message(such as in instant messaging apps).

The text can be in different lengths.

In android I solved this problem just by using 9 patch image format.

Is there any support for this format in UWP? If not, how should I solve my problem?

Thanks

JackPot16
  • 97
  • 1
  • 1
  • 10

2 Answers2

1

Please refer to NineGrid. enter image description here

Nine-grid rendering enables you to preserve the original dimensions of the corners (boxes 1, 3, 7, and 9). The top and bottom (boxes 2 and 8) are stretched horizontally only, and the sides (boxes 4 and 6) are stretched vertically only. The center (box 5) is stretched in both dimensions.

Code :

<Image Source="Images/9grid.bmp" NineGrid="30,20,30,20" />
ColeX
  • 14,062
  • 5
  • 43
  • 240
  • How can I set it as the background of a textblock? or as the background of grid? – JackPot16 Aug 07 '17 at 10:49
  • @JackPot16 this maybe helpful .:https://stackoverflow.com/questions/43761186/how-to-create-a-speech-bubble-in-uwp – ColeX Aug 08 '17 at 03:03
0

Place your TextBlock inside ViewBox. Set necessary dimensions:

<Grid Width="500" Height="200">
    <Ellipse Fill="PaleTurquoise"/>

    <Viewbox>
        <TextBlock Text="asd asdfpoiwe werolwejr ergfg qwe" FontSize="64" TextWrapping="Wrap" />
    </Viewbox>
</Grid>

Also this can be achieved via Composition.UI API. Let me know if you need.

Jet Chopper
  • 1,478
  • 13
  • 22