문제

I'm new in WPF, implementing the application using MVVM pattern. Border is container which contain path and textblock. textblock contain number. Width and height of border control binded with viewmodel property. want to show textblock contain i.e. number in middle of border container and path object on left top side of border container. how to set the position of textblock in middle of border control.

<Border BorderThickness="5" BorderBrush="#FF30333A" Width="{Binding Width}" Background="#FF1C2125"
                        Height="{Binding Height}"
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                        <Path  Name="starPath" Fill="Gray" Data="M 9,0 L 7,6 L 0,6 L 6,11 L 4,17 L 9,12 L 14,17 L 12,11 L 18,6 L 11,6 L 9,0">
                            </Path>

                        <TextBlock Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="1" Text="2"  VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="20"  Foreground="White" Background="Gray">
                        </TextBlock>
                    </Grid>
                </Border>
도움이 되었습니까?

해결책

Try this : 


<Border BorderThickness="5" BorderBrush="#FF30333A" Width="{Binding Width}" background="#FF1C2125" Height="{Binding Height}">
   <Grid>
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto"/>
         <RowDefinition Height="*"/>
      </Grid.RowDefinitions>

      <Path Grid.Row="0" HorizontalAlignment="Left"  Name="starPath" Fill="Gray" Data="M 9,0 L 7,6 L 0,6 L 6,11 L 4,17 L 9,12 L 14,17 L 12,11 L 18,6 L 11,6 L 9,0"/>

      <TextBloc Grid.Row="1" Text="2" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="20"/>
   </Grid>
</Border>

So ? does it works ?

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top