问题是是否可以创建/更改 CalendarItem 的样式,以便您还可以显示 BlackoutDates 模型中的附加值(粗略地说是一个数字)?
我只想在从模型中获取 16 和 BlackoutDates 的情况下得到这样的东西。上图日期根据“选择”范围而变化,不幸的是我无法为屏幕执行此操作。这意味着第一组 BlackoutDates (1-14) 包含数字 16,第二组 (15) 17,第三组 (23-28) 18。这就是你想要的那种逻辑。可能吗?
据我了解 Calendar.BlackoutDates 可以通过 Attached.property 绑定
我将建议的更改添加到 CalendarDayButtonStyle 样式。我抛弃了所有我不需要的动作(我希望)。
<Style x:Key="CalendarDayButtonStyle1" TargetType="{x:Type CalendarDayButton}">
<Setter Property="MinWidth" Value="5"/>
<Setter Property="MinHeight" Value="5"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="Height" Value="25"/>
<Setter Property="Width" Value="25"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CalendarDayButton}">
<Grid >
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="BlackoutDayStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="NormalDay"/>
<VisualState x:Name="BlackoutDay">
<Storyboard>
<!--<DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Blackout"/>-->
<DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TodayBackground"/>
<DoubleAnimation Duration="0" To=".5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="UpName"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="TodayBackground" Fill="#FFAAAAAA" Opacity="0" RadiusY="1" RadiusX="1"/>
<Border BorderThickness="1" BorderBrush="DarkGray"/>
<Rectangle x:Name="SelectedBackground" Fill="#FFBADDE9" Opacity="0" RadiusY="1" RadiusX="1"/>
<ContentPresenter x:Name="NormalText"
TextElement.Foreground="#FF333333"
Margin="5,1,2,1"
TextElement.FontSize="11"
HorizontalAlignment="Right"
VerticalAlignment="Bottom"
/>
<Label x:Name="UpName" Content="16" FontSize="9" Padding="0" Opacity="0" BorderThickness="1" BorderBrush="LightGray" VerticalAlignment="Top" HorizontalAlignment="Left"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
计划绑定到元素UpName
总的来说,我完成了这个项目,其中包含一个不可点击的月份范围显示和附加信息。只能通过多重绑定和转换器来连接日历元素。一般来说是这样的。
XAML
类模型
元素类继承自实现接口的 BaseModel
INotifyPropertyChanged,INotifyPropertyChanged
BindingProxy 是个很酷的东西
约定,我想不出比多重绑定更好的方法