当指定自定义 CalendarStyle 时,无法在 Silverlight DatePicker 中更改月份
我采用了 DatePicker 并自定义了在平板电脑上使用的样式。我发现虽然可以选择日期,但无法更改月份。尽管应用了鼠标悬停样式,但单击上一个/下一个按钮或月份名称都没有任何影响。
我采用了默认的日历样式并插入了一个 Viewbox 来增加大小,按照 Mike Taulty 的建议: http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/11/17/touched-part-5-touch-ready-controls.aspx
<Style TargetType="controls:Calendar" x:Key="TabletCalendar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Calendar" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
<StackPanel x:Name="Root" HorizontalAlignment="Center" >
<Viewbox Width="480" Height="440">
<controlsPrimitives:CalendarItem x:Name="CalendarItem" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" xmlns:controlsPrimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls" />
</Viewbox>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="controls:DatePicker" x:Key="TabletDatePicker">
<Setter Property="CalendarStyle" Value="{StaticResource TabletCalendar}" />
.....
</Style>
I've taken a DatePicker and customised the style for usage on a tablet. I'm finding that while days can be selected the month cannot be changed. Neither clicking the previous/next button or on the month name has any affect, although the mouseover style is applied.
I've taken the default Calendar style and inserted a Viewbox to increase the size, as suggested by Mike Taulty: http://mtaulty.com/CommunityServer/blogs/mike_taultys_blog/archive/2010/11/17/touched-part-5-touch-ready-controls.aspx
<Style TargetType="controls:Calendar" x:Key="TabletCalendar">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:Calendar" xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">
<StackPanel x:Name="Root" HorizontalAlignment="Center" >
<Viewbox Width="480" Height="440">
<controlsPrimitives:CalendarItem x:Name="CalendarItem" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" xmlns:controlsPrimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls" />
</Viewbox>
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="controls:DatePicker" x:Key="TabletDatePicker">
<Setter Property="CalendarStyle" Value="{StaticResource TabletCalendar}" />
.....
</Style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过将视图框在视觉树中向上移动一个级别来修复,不知道为什么这里会出现错误,但现在工作正常!
Fixed by moving the Viewbox up a level in the visual tree, not sure why there was a fault here but is working fine now!