Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WPF-在网格单元中追加字符串内容_Wpf_Grid_Alignment - Fatal编程技术网

WPF-在网格单元中追加字符串内容

WPF-在网格单元中追加字符串内容,wpf,grid,alignment,Wpf,Grid,Alignment,我有一个包含2X2网格的工具提示(参见下面的代码)。第1行第1列中的值是动态赋值的,但我想将其附加到左侧单元格中的字符串中 示例:用户应看到: 默认值:0.5,最小值:0,最大值:1092,当前值:2 但现在它是这样写的: 默认值:0.5,最小值:0,最大值:1092,当前:(此处有多个空格)2 看起来应该很简单,但我不能完全让它工作。或者,我希望至少将此值与单元格左侧对齐,因为它当前似乎位于中心,但HorizontalContentAlignment=“left”似乎不起作用。有什么想法吗 &

我有一个包含2X2网格的工具提示(参见下面的代码)。第1行第1列中的值是动态赋值的,但我想将其附加到左侧单元格中的字符串中

示例:用户应看到:

默认值:0.5,最小值:0,最大值:1092,当前值:2

但现在它是这样写的:

默认值:0.5,最小值:0,最大值:1092,当前:(此处有多个空格)2

看起来应该很简单,但我不能完全让它工作。或者,我希望至少将此值与单元格左侧对齐,因为它当前似乎位于中心,但HorizontalContentAlignment=“left”似乎不起作用。有什么想法吗

<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Label Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2">Time after removing all keycards that the relay will switch states</Label>
<Label Grid.Column="0" Grid.Row="1" >Default: 0.5, Min: 0, Max: 1092, Current:</Label>
<Label Grid.Column="1" Grid.Row ="1">
<Label.Content>
<Binding Path="EgressTimeout"
Converter="{StaticResource timeConverter}" />
</Label.Content>
</Label>
</Grid>

卸下所有钥匙卡后,继电器将切换状态的时间
默认值:0.5,最小值:0,最大值:1092,当前值:

您看到的问题是,在不定义网格和/或列宽的情况下,会使它们的大小相同,并占用容器中的所有可用空间。您看到的“多个空格”是第一列的剩余宽度,它是整个容器宽度的50%,即它的写入方式。添加ShowGridLines=“true”属性以了解我的意思

要消除多余的空间,可以将第一列的宽度设置为“自动”或其他定义的宽度

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition />
        <RowDefinition />
    </Grid.RowDefinitions>
    <Grid x:Name="yourOriginalGrid" ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition />
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition />
            <RowDefinition />
        </Grid.RowDefinitions>
        <Label Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2">Time after removing all keycards that the relay will switch states</Label>
        <Label Grid.Column="0" Grid.Row="1" >Default: 0.5, Min: 0, Max: 1092, Current:</Label>
        <Label Grid.Column="1" Grid.Row ="1">1492</Label>
    </Grid>
    <Grid Grid.Row="1" Background="Azure" ShowGridLines="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <TextBlock Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2">Time after removing all keycards that the relay will switch states</TextBlock>
        <TextBlock Grid.Column="0" Grid.Row="1" >Default: 0.5, Min: 0, Max: 1092, Current:</TextBlock>
        <TextBlock Grid.Column="1" Grid.Row ="1" Margin="2 0">1492</TextBlock>
    </Grid>
</Grid>

卸下所有钥匙卡后,继电器将切换状态的时间
默认值:0.5,最小值:0,最大值:1092,当前值:
1492
卸下所有钥匙卡后,继电器将切换状态的时间
默认值:0.5,最小值:0,最大值:1092,当前值:
1492

非常感谢!我会玩玩它,看看它是如何工作的。查看网格线将非常有帮助。