Xaml 将文本块对齐成圆形UWP
我想像这样把12个文本块对齐成一个圆圈Xaml 将文本块对齐成圆形UWP,xaml,uwp,uwp-xaml,Xaml,Uwp,Uwp Xaml,我想像这样把12个文本块对齐成一个圆圈 <Grid > <Grid.RowDefinitions> <RowDefinition Height="24"></RowDefinition> <RowDefinition Height="24"></RowDefinition> <RowDefin
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="9" Grid.Column="0" Grid.Row="3"></TextBlock>
<TextBlock Text="10" Grid.Column="1" Grid.Row="2"></TextBlock>
<TextBlock Text="11" Grid.Column="2" Grid.Row="1"></TextBlock>
<TextBlock Text="12" Grid.Column="3" Grid.Row="0"></TextBlock>
<TextBlock Text="1" Grid.Column="4" Grid.Row="1"></TextBlock>
<TextBlock Text="2" Grid.Column="5" Grid.Row="2"></TextBlock>
<TextBlock Text="3" Grid.Column="6" Grid.Row="3"></TextBlock>
<TextBlock Text="4" Grid.Column="5" Grid.Row="4"></TextBlock>
<TextBlock Text="5" Grid.Column="4" Grid.Row="5"></TextBlock>
<TextBlock Text="6" Grid.Column="3" Grid.Row="6"></TextBlock>
</Grid>
为了达到这个目的,我尝试过这样的方法
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
<RowDefinition Height="24"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
<ColumnDefinition Width="24"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="9" Grid.Column="0" Grid.Row="3"></TextBlock>
<TextBlock Text="10" Grid.Column="1" Grid.Row="2"></TextBlock>
<TextBlock Text="11" Grid.Column="2" Grid.Row="1"></TextBlock>
<TextBlock Text="12" Grid.Column="3" Grid.Row="0"></TextBlock>
<TextBlock Text="1" Grid.Column="4" Grid.Row="1"></TextBlock>
<TextBlock Text="2" Grid.Column="5" Grid.Row="2"></TextBlock>
<TextBlock Text="3" Grid.Column="6" Grid.Row="3"></TextBlock>
<TextBlock Text="4" Grid.Column="5" Grid.Row="4"></TextBlock>
<TextBlock Text="5" Grid.Column="4" Grid.Row="5"></TextBlock>
<TextBlock Text="6" Grid.Column="3" Grid.Row="6"></TextBlock>
</Grid>
但这并不能给我一个好的圆,有没有其他方法可以实现标签排列成一个圆?如果你想创建一个好的圆,网格不是一个合适的解决方案。在画布中使用坐标系可能是创建良好圆的一种方法。假设我们需要一个大小为200*200的时钟。所以中心点
(x0,y0)
是(100100)
。我们知道,两个相邻数字之间的夹角是30。然后可以计算2点钟(x2,y2)的文本块的中心点
x2=x0+r*cos(Math.PI*angle/180.0)
和y2=y0-r*sin(Math.PI*angle/180.0)
其他文本块也是如此
已更新
我做了一个简单的样本
Xaml:
它看起来像什么:
我还没有完全理解这一点,请您再清楚一点。@None我已经更新了代码片段。请检查一下。
int r = 100;
//1 o'clock
// need to minus 10 to get Canvas.top and Canvas.lelf value because x1 y1 represent the center of the textblock not the center of the textblock
double x1 = 150 + r * Math.Cos(Math.PI * 60 / 180.0) - 10;
double y1 = 150 - r * Math.Sin(Math.PI * 60 / 180.0) - 10;
textblock1.SetValue(Canvas.LeftProperty, x1);
textblock1.SetValue(Canvas.TopProperty, y1);
//2 o'clock
double x2 = 150 + r * Math.Cos(Math.PI * 30 / 180.0)-10;
double y2 = 150 - r * Math.Sin(Math.PI * 30 / 180.0)-10;
textblock2.SetValue(Canvas.LeftProperty, x2);
textblock2.SetValue(Canvas.TopProperty, y2);