2017-02-22 62 views
1

我有一個ListViewGridView。所述GridViewColumns的兩個有頭寬度小於在DataTemplate定義的內容,如圖WPF GridViewCellTemplate和GridViewColumnHeader寬度問題

in the figure

的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> 

任何幫助真的很感激! 謝謝

+0

Width屬性中有一個轉換器。你能發佈代碼嗎? –

回答

0

解決。我用一個Grid替換StackPanel。

<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>