Created
December 23, 2018 00:17
-
-
Save PiN73/f930b23d91c493d65fe74b7b9faa7aaa to your computer and use it in GitHub Desktop.
WPF TextBlock that is centered inside given rectangle in Canvas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Windows; | |
using System.Windows.Controls; | |
using System.Windows.Media; | |
class CenteredTextBlock: Grid | |
{ | |
private TextBlock textBlock = new TextBlock | |
{ | |
HorizontalAlignment = HorizontalAlignment.Center, | |
VerticalAlignment = VerticalAlignment.Center, | |
}; | |
public string Text | |
{ | |
get { return textBlock.Text; } | |
set { textBlock.Text = value; } | |
} | |
public Brush Foreground | |
{ | |
get { return textBlock.Foreground; } | |
set { textBlock.Foreground = value; } | |
} | |
public double FontSize | |
{ | |
get { return textBlock.FontSize; } | |
set { textBlock.FontSize = value; } | |
} | |
public CenteredTextBlock() | |
{ | |
Children.Add(textBlock); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment