0

IsSharedSizeScope 在 Grid(parent) 级别中设置为 true,StackPanel 作为子级,然后 IsSharedSizeScope 属性不起作用,但是当我删除 StackPanel 时它起作用。我试图了解我做错了什么。任何帮助,将不胜感激。

<Window x:Class="DemoWpfApp.Views.PortConnectionView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:DemoWpfApp.Views"
             xmlns:vm="clr-namespace:DemoWpfApp.ViewModels"
             mc:Ignorable="d" 
             d:DesignHeight="450" d:DesignWidth="800">
    <Window.DataContext>
        <vm:PortConnectionViewModel/>
    </Window.DataContext>

    <Grid Grid.IsSharedSizeScope="True">

        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
            <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
            <ColumnDefinition Width="Auto" SharedSizeGroup="A" />
        </Grid.ColumnDefinitions>

        <StackPanel Grid.Row="1" Orientation="Horizontal" Margin="3">
            <TextBlock Grid.Column="0" Text="Detect charger" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <TextBlock Grid.Column="1" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </StackPanel>

        <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="3">
            <TextBlock Grid.Column="0" Text="Configure meter" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <TextBlock Grid.Column="1" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </StackPanel>

        <StackPanel Grid.Row="3" Orientation="Horizontal" Margin="3">
            <TextBlock Grid.Column="0" Text="Activate charger" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <TextBlock Grid.Column="1" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </StackPanel>

        <StackPanel Grid.Row="4" Orientation="Horizontal" Margin="3">
            <TextBlock Grid.Column="1" Text="Upgrade version" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
            <TextBlock Grid.Column="2" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
        </StackPanel>

    </Grid>
</Window>
4

1 回答 1

0

Grid.Column在 TextBlocks 上无关紧要,因为它们并不直接在Grid. 明确的问题陈述是解决方案的一半:将 TextBlocks 直接放在 Grid 内(在适当的行中)。

<Grid Grid.IsSharedSizeScope="True">

    <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
        <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>

    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
        <ColumnDefinition Width="Auto" SharedSizeGroup="A"/>
        <ColumnDefinition Width="Auto" SharedSizeGroup="A" />
    </Grid.ColumnDefinitions>

    <TextBlock Grid.Row="1" Grid.Column="0" Text="Detect charger" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <TextBlock Grid.Row="1" Grid.Column="1" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>

    <TextBlock Grid.Row="2" Grid.Column="0" Text="Configure meter" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <TextBlock Grid.Row="2" Grid.Column="1" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>

    <TextBlock Grid.Row="3" Grid.Column="0" Text="Activate charger" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <TextBlock Grid.Row="3"  Grid.Column="1" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>

    <TextBlock Grid.Row="4" Grid.Column="1" Text="Upgrade version" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
    <TextBlock Grid.Row="4" Grid.Column="2" Text="Ok" Margin="3" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
于 2019-12-16T11:40:37.520 回答