C# wpf中的变更控制中心

C# wpf中的变更控制中心,c#,wpf,C#,Wpf,我有一些标签“我的文本”。 我有一些UserControl,里面有文本(“文本部分”),还有一些靠近文本的可视部分 左图是我想要实现的。对,这就是我得到的 我希望我的UserControl的中心不是默认中心,而是自定义点。 因为“我的文本”的长度可能不同,同时它应该相对于控件“文本部分”的中心居中 目标^当前^ 您将需要定义单独的列,其中一列居中用于居中文本,另一列用于视觉标签 现在棘手的部分是将UserControl内部的一列与外部的一列同步。您可以为此使用SharedSizeGroup,就

我有一些
标签
“我的文本”。 我有一些
UserControl
,里面有文本(“文本部分”),还有一些靠近文本的可视部分

左图是我想要实现的。对,这就是我得到的

我希望我的
UserControl
的中心不是默认中心,而是自定义点。 因为“我的文本”的长度可能不同,同时它应该相对于控件“文本部分”的中心居中

目标^当前^

您将需要定义单独的列,其中一列居中用于居中文本,另一列用于视觉标签

现在棘手的部分是将UserControl内部的一列与外部的一列同步。您可以为此使用SharedSizeGroup,就像在本例中一样,为了方便起见,我只使用了ContentControl而不是UserControl:

   <Grid IsSharedSizeScope="True">
  <Grid.RowDefinitions>
     <RowDefinition Height="Auto"/>
     <RowDefinition Height="Auto"/>
  </Grid.RowDefinitions>
  <Grid HorizontalAlignment="Stretch" Background="Red">
     <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
     </Grid.RowDefinitions>
     <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="colLeft"/>
        <ColumnDefinition Width="Auto" SharedSizeGroup="colRight"/>
     </Grid.ColumnDefinitions>
     <Label HorizontalAlignment="Center" Background="LightBlue">MyText</Label>
  </Grid>
  <ContentControl Grid.Row="1">
     <Grid HorizontalAlignment="Stretch" Background="Yellow">
        <Grid.RowDefinitions>
           <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
           <ColumnDefinition Width="Auto" SharedSizeGroup="colLeft"/>
           <ColumnDefinition Width="Auto" SharedSizeGroup="colRight"/>
        </Grid.ColumnDefinitions>
        <Label HorizontalAlignment="Center" Background="Lime">text part a little longer
        </Label>
        <Label Grid.Column="1">someVisualLabel</Label>
     </Grid>
  </ContentControl>

我的文本
文本部分稍微长一点
一些视觉标签

请张贴您尝试过的代码,供其他人检查