我有以下矩形,填充颜色.我想在框中间添加一些文字.请提出一些解决方案.
var rect1 = new Rectangle { Stroke = new SolidColorBrush(Colors.Red), Fill = new SolidColorBrush(Colors.Black), Width = 150, Height = 100, VerticalAlignment = System.Windows.VerticalAlignment.Top, HorizontalAlignment = System.Windows.HorizontalAlignment.Left }; Grid.SetRow(rect, 0); TGrid2.Children.Add(rect1);
基本上我想做一个拖放功能.其中rect1将被拖到rect2上; 只有边框颜色和透明的Fill-body和on drop用rect1替换rect2.这就是为什么我做了一个矩形,现在试图想象如何在矩形中添加文本作为中心内容,类似于按钮.
替换为Rectangle
a Grid
或a Border
并放入TextBlock
内部.
如果你绝对必须使用一个矩形,你可以伪造它!
<Grid> <Rectangle Fill="Red"/> <TextBlock Text="Hi there" Margin="5"/> </Grid>