WPF GridViewCellTemplate 和 GridViewColumnHeader 宽度问题
WPF GridViewCellTemplate and GridViewColumnHeader width issue
我有一个 ListView
和一个 GridView
。其中两个 GridViewColumns
的 header 宽度小于 DataTemplate
中定义的内容,如图
XAML定义如下:
<GridViewColumn Header="{lex:Loc Lang:minTemperature}" x:Name="MinTemperatureColumn"
Width="{Binding IsVisible, Converter={StaticResource BoolToSizeConverter}}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<xctk:DoubleUpDown
Value="{Binding AdditionalData.MinTemperature, Converter={StaticResource TemperatureToTemperatureConverter}, Mode=TwoWay}"
Style="{DynamicResource TemperatureDoubleUpDown}"
Minimum="{Binding AbsoluteTemperatureMinimum, RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Window}}"
ValueChanged="OnRunDataChanged" />
<TextBlock
Text="{Binding TemperatureUnitMeasure, RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Window}}"
Margin="3"
VerticalAlignment="Center"
Foreground="{DynamicResource StandardForegroundColor}" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Xceed风格的XAML如下:
<Style x:Key="TemperatureDoubleUpDown" TargetType="{x:Type xctk:DoubleUpDown}"
BasedOn="{StaticResource {x:Type xctk:DoubleUpDown}}">
<Setter Property="FontSize" Value="18" />
<Setter Property="Width" Value="Auto" />
<Setter Property="Increment" Value="1" />
<Setter Property="FormatString" Value="N0" />
</Style>
非常感谢任何帮助!
谢谢
已解决。我将 StackPanel 替换为 Grid。
<GridViewColumn Header="{Binding MinTemperatureUnitMeasure, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
x:Name="MinTemperatureColumn"
Width="{Binding IsCurrentJobTermocamera, Converter={StaticResource BoolToSizeConverter}}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<xctk:DoubleUpDown
Grid.Column="0"
Margin="5"
Value="{Binding AdditionalData.MinTemperature, Converter={StaticResource TemperatureToTemperatureConverter}, Mode=TwoWay}"
Style="{DynamicResource TemperatureDoubleUpDown}"
Minimum="{Binding AbsoluteTemperatureMinimum, RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Window}}"
ValueChanged="OnRunDataChanged"
HorizontalAlignment="Stretch"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
我有一个 ListView
和一个 GridView
。其中两个 GridViewColumns
的 header 宽度小于 DataTemplate
中定义的内容,如图
XAML定义如下:
<GridViewColumn Header="{lex:Loc Lang:minTemperature}" x:Name="MinTemperatureColumn"
Width="{Binding IsVisible, Converter={StaticResource BoolToSizeConverter}}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<xctk:DoubleUpDown
Value="{Binding AdditionalData.MinTemperature, Converter={StaticResource TemperatureToTemperatureConverter}, Mode=TwoWay}"
Style="{DynamicResource TemperatureDoubleUpDown}"
Minimum="{Binding AbsoluteTemperatureMinimum, RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Window}}"
ValueChanged="OnRunDataChanged" />
<TextBlock
Text="{Binding TemperatureUnitMeasure, RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Window}}"
Margin="3"
VerticalAlignment="Center"
Foreground="{DynamicResource StandardForegroundColor}" />
</StackPanel>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
Xceed风格的XAML如下:
<Style x:Key="TemperatureDoubleUpDown" TargetType="{x:Type xctk:DoubleUpDown}"
BasedOn="{StaticResource {x:Type xctk:DoubleUpDown}}">
<Setter Property="FontSize" Value="18" />
<Setter Property="Width" Value="Auto" />
<Setter Property="Increment" Value="1" />
<Setter Property="FormatString" Value="N0" />
</Style>
非常感谢任何帮助! 谢谢
已解决。我将 StackPanel 替换为 Grid。
<GridViewColumn Header="{Binding MinTemperatureUnitMeasure, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=Window}}"
x:Name="MinTemperatureColumn"
Width="{Binding IsCurrentJobTermocamera, Converter={StaticResource BoolToSizeConverter}}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<xctk:DoubleUpDown
Grid.Column="0"
Margin="5"
Value="{Binding AdditionalData.MinTemperature, Converter={StaticResource TemperatureToTemperatureConverter}, Mode=TwoWay}"
Style="{DynamicResource TemperatureDoubleUpDown}"
Minimum="{Binding AbsoluteTemperatureMinimum, RelativeSource={RelativeSource
Mode=FindAncestor, AncestorType=Window}}"
ValueChanged="OnRunDataChanged"
HorizontalAlignment="Stretch"/>
</Grid>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>