我想在Windows应用商店应用程序中以编程方式添加TextBlock边框。 我怎样才能做到这一点? 谢谢。
答案 0 :(得分:0)
创建新项目并在OnNavigatedTo
事件中添加此代码。
protected override void OnNavigatedTo(NavigationEventArgs e)
{
var tb = new TextBlock()
{
Text = "...TextBlock with border...",
FontSize = 20
};
//To get actual height and width of TextBlock
tb.Arrange(new Rect(0, 0, Window.Current.Bounds.Width, Window.Current.Bounds.Height));
tb.Measure(new Size(Window.Current.Bounds.Width, Window.Current.Bounds.Height));
var border = new Border()
{
BorderThickness = new Thickness(3),
BorderBrush = new SolidColorBrush(Windows.UI.Colors.Red),
Height = tb.ActualHeight + 10,
Width = tb.ActualWidth + 10
};
var rootGrid = (Grid)(((Page)this).Content);
rootGrid.Children.Add(border);
border.Child = tb;
}