2015-08-29 48 views
0

我想設計我的WPF窗口的佈局來添加一些代碼列表項,我需要使用DatePicker,但日曆按鈕在文本框中不可見。Datepicker按鈕不出現

這是我的網格:

<Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="35"></RowDefinition> 
      <RowDefinition Height="35"></RowDefinition> 
      <RowDefinition Height="*"></RowDefinition> 
     </Grid.RowDefinitions> 

     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="auto"></ColumnDefinition> 
      <ColumnDefinition Width="*"></ColumnDefinition> 
      <ColumnDefinition Width="auto"></ColumnDefinition> 
      <ColumnDefinition Width="*"></ColumnDefinition> 
     </Grid.ColumnDefinitions> 

     <Label Content="Code" Grid.Column="0" Grid.Row="0" /> 
     <TextBox Text="{Binding Path=Code}" Grid.Column="1" Grid.Row="0" MinWidth="160" MaxLength="30" MaxWidth="160" /> 

     <Label Content="Description" Grid.Column="0" Grid.Row="1" /> 
     <TextBox Text="{Binding Path=Description}" Grid.Column="1" Grid.Row="1" MinWidth="160" MaxLength="120" MaxWidth="160" /> 

     <Label Content="Valid from" Grid.Column="2" Grid.Row="0" /> 
     <DatePicker Name="dpValidFrom" VerticalAlignment="Top" Grid.Column="3" Grid.Row="0" /> 

     <Label Content="Valid to" Grid.Column="2" Grid.Row="1" /> 
     <DatePicker Name="dpValidTo" VerticalAlignment="Top" Grid.Column="3" Grid.Row="1" /> 
    </Grid> 

在設計模式中看到這一點:

In design mode a see this

但在應用程序,我看到這一點: but in app i see this

有人知道爲什麼? 感謝您的建議

回答

1

我沒有使用Windows 10 VS 2015的任何問題。雖然,根據您的屏幕截圖,它看起來像是某種類型的默認MarginPadding。使用這個:

<Grid> 
    <Grid.RowDefinitions> 
     <RowDefinition Height="35"></RowDefinition> 
     <RowDefinition Height="35"></RowDefinition> 
     <RowDefinition Height="*"></RowDefinition> 
    </Grid.RowDefinitions> 

    <Grid.ColumnDefinitions> 
     <ColumnDefinition Width="auto"></ColumnDefinition> 
     <ColumnDefinition Width="*"></ColumnDefinition> 
     <ColumnDefinition Width="auto"></ColumnDefinition> 
     <ColumnDefinition Width="*"></ColumnDefinition> 
    </Grid.ColumnDefinitions> 

    <Grid.Resources> 
     <Style TargetType="DatePicker"> 
      <Setter Property="Margin" Value="0"/> 
      <Setter Property="Padding" Value="0"/> 
      <Setter Property="HorizontalContentAlignment" Value="Stretch"/> 
      <Setter Property="VerticalContentAlignment" Value="Center"/> 
      <Setter Property="VerticalAlignment" Value="Stretch"/> 
     </Style> 
    </Grid.Resources> 
    <Label Content="Code" Grid.Column="0" Grid.Row="0" /> 
    <TextBox Text="{Binding Path=Code}" Grid.Column="1" Grid.Row="0" MinWidth="160" MaxLength="30" MaxWidth="160" /> 

    <Label Content="Description" Grid.Column="0" Grid.Row="1" /> 
    <TextBox Text="{Binding Path=Description}" Grid.Column="1" Grid.Row="1" MinWidth="160" MaxLength="120" MaxWidth="160" /> 

    <Label Content="Valid from" Grid.Column="2" Grid.Row="0" /> 
    <DatePicker Name="dpValidFrom" Grid.Column="3" Grid.Row="0" /> 

    <Label Content="Valid to" Grid.Column="2" Grid.Row="1" /> 
    <DatePicker Name="dpValidTo" Grid.Column="3" Grid.Row="1" /> 
</Grid>