Hello,
I am attempting to set the alignment of text in a LiveTile object to be in the center, but it only works if the LiveTile object does not have badges.I have uploaded an example image. It's visible that there are too many unnecessary spaces between the text and the badge. It seems like the text is always centered to the left even though the alignment is set to center.
This is the code I use:
Could you please help me to achieve my goal?
Hi,
I'm not sure if it's possible to do this with TileMediumImage. In fact, I'm not even sure I understand exactly how you got the badge numbers to show up here. You may have to create your own custom tile in order to have that much control over the exactly position and alignment of the text. But it's hard to say from just a code snippet like this. There are too many unknowns here. I don't know what TileSize you are setting, I don't know what your SetImageAynch method is doing, I don't even know what the text on the tile is although I can guess it says something like "Appointments", etc.
Can you provide me with a working sample that has what you have working so far so I can see if there's anything that can be done? Like I said, I am pretty sure you will need a custom tile rather than TileMediumImage, but it might also be possible to use a CreationFilter. It's tough to say for sure without more specific information.
Also... where exactly do you want the text to be centered to? I mean, presumably, the badge (number) is going to eat up some of the space, so the text would be centered in the available space, which means it would not be centered on the image and that might look kinda weird. It also wouldn't gain you any extra room so if the text is clipped when aligned left, it will be clipped even more if it's centered.
Hi Mike,
Thanks for your response.
It is very simple to reproduce this one. Even if I don't use badges, I cannot set my text alignment to center. The text will not be aligned exactly to center.
You can simply make a new LiveTile class and set a text and you will see that the text never aligns exactly to the center.
I created a new simple project to provide you with a working sample.
The TileSize does not matter, but lets say I want a simple LiveTile and set the tilesize to Wide and I don't want any badges. There is no option to set the alignment exactly to the center, even if i don't want to send badge notifications.
I simply want a StaticTile or LiveTile with center aligned text and Wide tilesize.
Is there anybody that can help me out with this problem?
Hi Ali,
It would be a lot easier if you were able to use the form designer. But your sample won't even let me open the form since you have written custom code in the InitializeComponent that doesn't compile at design-time.
Anyway, what you want should be easy enough to achieve using a custom tile. I am attaching a sample here with a single wide tile with centered text. The way I created this was as follows:
1) Create a new project and put a LiveTileView on the form designer.
2) Right-click the LiveTileView and select LiveTileViewDesigner
3) Go to the Templates tab, select the Wide group and then scroll to the bottom. The last item on the list is LiveTileWideCustomContent. Drag this onto the LiveTileView.
4) Click on this new tile in the LiveTileView and then click the pencil (lower left corner) to edit. Select the tile frame under Wide Frames. Click the pencil again to edit this frame.
5) From here you can edit the custom tile frame's content. Add a text block and arrange it so it spans the entire width of the frame. I also set the TextSize to something smaller (like Normal) so that there is room and you can see the centering.
6) Go to the Appearance on the TextBlock and go to the TextHAlign property. Set it to Center.
7) Click OK three times to commit the changes.
And that's it. A wide tile with centered text.
Thanks for describing the steps, but if you look at your sample project, you can see it is not EXACTLY centered.
If you replace the text 'imageblock1' with '32952305353' or something else, you can see and feel it better that it is not centered.
You are right. It's a little off. I went back into my sample and took another look. It looks like what's happening here is that when I positioned the TextBlock on the custom tile, it is snapping to a grid and the grid isn't perfectly aligned to the edges of the tile. So my text block was extended off the edge of the tile.
This is easily fixed. I went to the Location property of the TextBlock and explicitly set the X position to 0. Then I went to the width and explicitly set it to the width of the tile (247).
It works like a charm. Thank you very much for your help!