Uwp CalendarDatePicker 日期控件【透明样式】

效果截图:

页面Page:

<CalendarDatePicker  Style="{StaticResource CalendarDatePickerStyle1}"/>

资源字典CalendarDatePickerStyle1:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <Style x:Key="CalendarDatePickerStyle1" TargetType="CalendarDatePicker">
        <Setter Property="Foreground" Value="{ThemeResource CalendarDatePickerForeground}"/>
        <Setter Property="Background" Value="{ThemeResource CalendarDatePickerBackground}"/>
        <Setter Property="BorderBrush" Value="{ThemeResource CalendarDatePickerBorderBrush}"/>
        <Setter Property="BorderThickness" Value="{ThemeResource CalendarDatePickerBorderThemeThickness}"/>
        <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="UseSystemFocusVisuals" Value="{ThemeResource IsApplicationFocusVisualKindReveal}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CalendarDatePicker">
                    <Grid x:Name="Root">
                        <FlyoutBase.AttachedFlyout>
                            <Flyout Placement="Bottom">
                                <Flyout.FlyoutPresenterStyle>
                                    <Style TargetType="FlyoutPresenter">
                                        <Setter Property="Padding" Value="0"/>
                                        <Setter Property="BorderThickness" Value="0"/>
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="FlyoutPresenter">
                                                    <ContentPresenter BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentTransitions="{TemplateBinding ContentTransitions}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                                        <ContentPresenter.Background>
                                                            <SolidColorBrush Opacity="0.2" Color="Black"></SolidColorBrush>
                                                        </ContentPresenter.Background>
                                                    </ContentPresenter>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </Flyout.FlyoutPresenterStyle>

                                <CalendarView Foreground="#2775B6"  BlackoutForeground="#2775B6" CalendarItemForeground="#2775B6" PressedBorderBrush="#2177B8"
                                              x:Name="CalendarView"  CalendarIdentifier="{TemplateBinding CalendarIdentifier}" DisplayMode="{TemplateBinding DisplayMode}" DayOfWeekFormat="{TemplateBinding DayOfWeekFormat}" FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}" IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" IsOutOfScopeEnabled="{TemplateBinding IsOutOfScopeEnabled}" IsGroupLabelVisible="{TemplateBinding IsGroupLabelVisible}" MinDate="{TemplateBinding MinDate}" MaxDate="{TemplateBinding MaxDate}" Style="{TemplateBinding CalendarViewStyle}">
                                    <CalendarView.Background>
                                        <SolidColorBrush Opacity="0.2" Color="Black"></SolidColorBrush>
                                    </CalendarView.Background>
                                    <CalendarView.BorderBrush>
                                        <SolidColorBrush Opacity="0.2" Color="Black"></SolidColorBrush>
                                    </CalendarView.BorderBrush>
                                    <CalendarView.TodayForeground>
                                        <AcrylicBrush  TintColor="#D8E3E7"/>
                                    </CalendarView.TodayForeground>
                                    <CalendarView.OutOfScopeBackground>
                                        <SolidColorBrush Opacity="0.4" Color="#144A74"></SolidColorBrush>
                                    </CalendarView.OutOfScopeBackground>
                                    <CalendarView.OutOfScopeForeground>
                                        <SolidColorBrush Color="#93B5CF"></SolidColorBrush>
                                    </CalendarView.OutOfScopeForeground>
                                </CalendarView>
                                
                            </Flyout>
                        </FlyoutBase.AttachedFlyout>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="32"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="32"/>
                        </Grid.RowDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="PointerOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#1661AB"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="black"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="black"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#1661AB"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="black"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="BorderBrush">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#1661AB"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="HeaderContentPresenter" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CalendarDatePickerHeaderForegroundDisabled}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DateText" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#4E7CA1"/>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="CalendarGlyph" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{ThemeResource CalendarDatePickerCalendarGlyphForegroundDisabled}"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="FocusStates">
                                <VisualState x:Name="Unfocused"/>
                                <VisualState x:Name="PointerFocused"/>
                                <VisualState x:Name="Focused">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Background" Storyboard.TargetProperty="Background">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="black"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="SelectionStates">
                                <VisualState x:Name="Unselected"/>
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DateText" Storyboard.TargetProperty="Foreground">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="#4E7CA1"/>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentPresenter x:Name="HeaderContentPresenter" ContentTemplate="{TemplateBinding HeaderTemplate}" Content="{TemplateBinding Header}" Margin="{ThemeResource ComboBoxHeaderThemeMargin}" TextWrapping="Wrap" Visibility="Collapsed" x:DeferLoadStrategy="Lazy"/>
                        <Border x:Name="Background"  BorderThickness="1" BorderBrush="#1661AB" Grid.ColumnSpan="2" Control.IsTemplateFocusTarget="True" Grid.Row="1">
                            <Border.Background>
                                <SolidColorBrush Color="Black" Opacity="0.4"></SolidColorBrush>
                            </Border.Background>
                        </Border>
                        <TextBlock x:Name="DateText" Foreground="#66A9C9" FontSize="15" HorizontalAlignment="Left" Padding="12, 0, 0, 2" Grid.Row="1" Text="{TemplateBinding PlaceholderText}" VerticalAlignment="Center"/>
                        <FontIcon x:Name="CalendarGlyph" Grid.Column="1" FontFamily="{ThemeResource SymbolThemeFontFamily}" Foreground="#1661AB" FontSize="16" Glyph="&#xE787;" HorizontalAlignment="Center" Grid.Row="1" VerticalAlignment="Center"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
WinUI 控件UWP 控件、WPF 控件和 Silverlight 控件在语法和结构上有所不同,因此可以通过检查 XAML 代码的命名空间来区分它们。以下是一些常见的命名空间和控件: - WinUI 控件:命名空间为 `http://schemas.microsoft.com/winui/2021/xaml/behaviors` 或 `http://schemas.microsoft.com/winui/2021/xaml/presentation`,控件名称以 `Microsoft.UI` 开头。 - UWP 控件:命名空间为 `http://schemas.microsoft.com/winfx/2006/xaml/presentation` 或 `http://schemas.microsoft.com/winfx/2008/xaml/presentation`,控件名称以 `Windows.UI` 开头。 - WPF 控件:命名空间为 `http://schemas.microsoft.com/winfx/2006/xaml/presentation` 或 `http://schemas.microsoft.com/netfx/2007/xaml/presentation`,控件名称以 `System.Windows` 或 `Microsoft.Windows` 开头。 - Silverlight 控件:命名空间为 `http://schemas.microsoft.com/winfx/2006/xaml/presentation` 或 `http://schemas.microsoft.com/client/2007`,控件名称以 `System.Windows.Controls` 或 `Microsoft.Windows.Controls` 开头。 可以通过读取 XAML 文件中的命名空间来确定使用的控件类型。例如,以下代码片段演示了如何读取 XAML 文件中的命名空间: ```csharp using System.Xml.Linq; // Load XAML file into an XDocument XDocument xdoc = XDocument.Load("MyXamlFile.xaml"); // Get the root element of the XAML file XElement root = xdoc.Root; // Get the default namespace of the XAML file XNamespace ns = root.GetDefaultNamespace(); // Check the namespace to determine the type of controls used in the XAML file if (ns.NamespaceName.StartsWith("http://schemas.microsoft.com/winui")) { // WinUI controls } else if (ns.NamespaceName.StartsWith("http://schemas.microsoft.com/winfx")) { // UWP or WPF controls } else if (ns.NamespaceName.StartsWith("http://schemas.microsoft.com/client")) { // Silverlight controls } else { // Unknown namespace } ``` 请注意,这只是一种简单的方法来区分不同类型的控件,实际上还需要考虑一些其他因素,例如控件的属性和行为。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值