使用DatePicker时遇到一些问题。有点卡住,可以使用一些帮助/新鲜看看问题。
目标是为DatePicker创建自定义样式,主要区别在于:
问题:
我在资源字典中使用自定义样式和密钥。
到目前为止,我通过了第一个目标,并看到第二个目标没有问题。但最后一个,男孩,似乎非常强硬。只有解决方案才能设置属性Focusable =" False",但它不是一个选项,因为它会切断手动输入日期的能力。
这是风格:
<Style x:Key="DatePicker" TargetType="{x:Type DatePicker}">
<Setter Property="Foreground" Value="{StaticResource DarkGrayBrush}" />
<Setter Property="Focusable" Value="True" />
<Setter Property="VerticalAlignment" Value="Top" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="HorizontalAlignment" Value="Left" />
<Setter Property="IsTodayHighlighted" Value="True" />
<Setter Property="SelectedDateFormat" Value="Short" />
<Setter Property="Padding" Value="0" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<!--Set CalendarStyle to DatePickerCalendarStyle.-->
<Setter Property="CalendarStyle"
Value="{DynamicResource DatePickerCalendarStyle}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DatePicker}">
<Border BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}"
CornerRadius="0"
Background="Transparent">
<Grid x:Name="PART_Root"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="150" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Button x:Name="PART_Button"
Grid.Column="1"
Foreground="{TemplateBinding Foreground}"
Focusable="True"
HorizontalAlignment="Left"
Margin="1,0,1,0"
Grid.Row="0"
VerticalAlignment="Center" Style="{StaticResource IconButtonStyle}">
<Image Source="/img/calendar.png" Height="20" />
</Button>
<Border BorderBrush="{StaticResource BlueBrush}"
BorderThickness="2"
CornerRadius="0"
Padding="0"
Width="150"
Height="23"
Background="{StaticResource WhiteBrush}">
<DatePickerTextBox x:Name="PART_TextBox"
Grid.Column="0"
Foreground="{TemplateBinding Foreground}"
Focusable="{TemplateBinding Focusable}"
FocusVisualStyle="{x:Null}"
HorizontalContentAlignment="Left"
Grid.Row="0"
SelectionBrush="{x:Null}"
VerticalContentAlignment="Center"
BorderThickness="0"
Background="Transparent"
Width="150">
</DatePickerTextBox>
</Border>
<Grid x:Name="PART_DisabledVisual"
Grid.ColumnSpan="2"
Grid.Column="0"
IsHitTestVisible="False"
Opacity="0"
Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Rectangle Grid.Column="0"
Fill="#A5FFFFFF"
RadiusY="1"
Grid.Row="0"
RadiusX="1" />
<Rectangle Grid.Column="1"
Fill="#A5FFFFFF"
Height="18"
Margin="3,0,3,0"
RadiusY="1"
Grid.Row="0"
RadiusX="1"
Width="19" />
<Popup x:Name="PART_Popup"
AllowsTransparency="True"
Placement="Bottom"
PlacementTarget="{Binding ElementName=PART_TextBox}"
StaysOpen="False" />
</Grid>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
任何帮助将不胜感激。
谢谢。
的更新:
这是指向solution的链接:
答案 0 :(得分:1)
您引用的高亮框架是由DatePicker控件中的内置可视状态(MouseOver)引起的,请尝试以下步骤:
将datepicker控件添加到项目中。
右键单击日期选择器并选择&#34;编辑模板\编辑副本...&#34;。
这将带你到模板设计师。
文本框实际上是datepicker控件中的另一个控件,您需要立即更改文本框的模板,查找名为&#34; Part_Texbox&#34;的控件,右键单击它并选择& #34;编辑模板\编辑副本......&#34;。
您需要更改&#34; MouseOver&#34;的值。视觉状态,请检查此图片:git branch
documentation