是否可以在UWP CalendarView中设置密度条的高度
我想知道,是否可以在UWP CalendarView控件中设置密度条的高度 亲切问候, Martin控件的日历网格由对象组成。我们可以使用是否可以在UWP CalendarView中设置密度条的高度,uwp,Uwp,我想知道,是否可以在UWP CalendarView控件中设置密度条的高度 亲切问候, Martin控件的日历网格由对象组成。我们可以使用CalendarViewDayItemChangingEventArgs的item属性修改控件事件中的day项目,以访问CalendarViewDayItem对象。密度条位于中 但为了提高性能,控件的可视元素直接由控件呈现,而不是在控件模板中定义为XAML元素。这意味着我们不能为这些元素设置样式或重新设置模板。尽管有几个“日历项目”和“日项目”属性可用于自定义
CalendarViewDayItemChangingEventArgs
的item
属性修改控件事件中的day项目,以访问CalendarViewDayItem对象。密度条位于中
但为了提高性能,控件的可视元素直接由控件呈现,而不是在控件模板中定义为XAML元素。这意味着我们不能为这些元素设置样式或重新设置模板。尽管有几个“日历项目”和“日项目”属性可用于自定义这些元素,但它们没有设置密度栏高度的属性。因此,我们无法修改样式以更改密度栏的高度
因此,根据您的要求,我们可以做一些替代的解决办法
如果您只是认为一个密度条没有很好地标记,可以提供两个或多个带有颜色的密度条,使其更加明显。
private void CalendarView_CalendarViewDayItemChanging(CalendarView sender, CalendarViewDayItemChangingEventArgs args)
{
List<Color> densityColors = new List<Color>();
densityColors.Add(Colors.Green);
densityColors.Add(Colors.Green);
args.Item.SetDensityColors(densityColors);
}
<Page.Resources>
<!-- Default style for CalendarViewDayItem -->
<Style TargetType="CalendarViewDayItem">
<Setter Property="MinWidth" Value="40" />
<Setter Property="MinHeight" Value="40" />
<Setter Property="Margin" Value="1" />
<Setter Property="Padding" Value="0, 0, 0,0" />
<Setter Property="UseSystemFocusVisuals" Value="{StaticResource UseSystemFocusVisuals}" />
<Setter Property="FocusVisualMargin" Value="-2" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="CalendarViewDayItem">
<!-- For CalendarViewDayItem, TextBlock visual is created and handled by code and we can't see it from the style. -->
<!-- CCalendarViewBaseItemChrome creates and appends a TextBlock in the visual after the ControlTemplate is applied -->
<!-- VSM needs a container and that's why Grid is added. But we don't need the rendering of Grid so We set width to 0 -->
<Grid x:Name="Root" Width="40" Height="8" Background="Red" VerticalAlignment="Bottom">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="PointerOver">
<VisualState.Setters>
<Setter Target="Root.(RevealBrush.State)" Value="PointerOver" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Target="Root.(RevealBrush.State)" Value="Pressed" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Page.Resources>