根据WPF网格中的内容重新调整列的大小

时间:2014-12-08 04:40:59

标签: c# wpf xaml

我正在尝试在调整窗口大小时根据其内容重新调整第4列中的内容呈现器的大小。但它不像我想要的那样表现。你能帮助我摆脱这个问题。

 <Grid Name="PART_grid1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1"/>
                                <ColumnDefinition Width="10"/>
                                <ColumnDefinition Width="22"/>
                                <ColumnDefinition Width="5"/>
                                <ColumnDefinition Width="27*"/>
                                <ColumnDefinition Width="10"/>
                                <ColumnDefinition Width="1"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="8"/>
                                <RowDefinition Height="21"/>
                                <RowDefinition Height="8"/>
                            </Grid.RowDefinitions>

                            <Path Data="M74,37L0,37 0,0 74,0z"  Grid.Column="1" Grid.Row="0" Stretch="Fill"  Grid.RowSpan="3" Grid.ColumnSpan="5">
                                <Path.Fill>
                                    <LinearGradientBrush EndPoint="0.5,0" StartPoint="0.5,1">
                                        <GradientStop Color="#FFF9F9F9" Offset="0"/>
                                        <GradientStop Color="#FFD7D7D7" Offset="1"/>
                                    </LinearGradientBrush>
                                </Path.Fill>
                            </Path>
                            <Path Data="F1M0,37L1,37 1,0 0,0z" Grid.Column="7" Grid.Row="0" Grid.RowSpan="3" Fill="#FF7D7D7D" />
                            <Path Data="F1M0,37L1,37 1,0 0,0z" Grid.Column="0" Grid.Row="0" Grid.RowSpan="3" Fill="White"/>


                            <Grid Grid.Column="2" Grid.Row="1">
                                <!--Image-->
                            </Grid>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Grid.Column="4" Width="Auto" Grid.Row="1" />
                        </Grid>

1 个答案:

答案 0 :(得分:1)

在列定义中使用Auto

<ColumnDefinition Width="Auto" />

它会自动适应内容。它应该在主网格的列定义中。目前您的价值为5,因此它非常狭窄。