Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xaml Windows Phone 8.1日期选择器自定义问题_Xaml_Datepicker_Windows Phone 8.1_Controltemplate - Fatal编程技术网

Xaml Windows Phone 8.1日期选择器自定义问题

Xaml Windows Phone 8.1日期选择器自定义问题,xaml,datepicker,windows-phone-8.1,controltemplate,Xaml,Datepicker,Windows Phone 8.1,Controltemplate,主要问题: 我有一个Windows Phone 8.1应用程序,其中有一个日期选择器: <DatePicker DateChanged="ChangedDate" x:Name="OriginationDate" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Style="{StaticResource CustomDatePickerStyle}" FontSize=

主要问题:

我有一个Windows Phone 8.1应用程序,其中有一个日期选择器:

<DatePicker 
    DateChanged="ChangedDate"  
    x:Name="OriginationDate" 
    Grid.Row="1" 
    Grid.Column="0" 
    Grid.ColumnSpan="2" 
    Style="{StaticResource CustomDatePickerStyle}"
    FontSize="{StaticResource TextStyleSmallFontSize}" 
    RequestedTheme="Light"
/>

我已使用以下控件模板覆盖了它:

<Style TargetType="DatePicker" x:Key="CustomDatePickerStyle">
    <Setter Property="Orientation" Value="Horizontal"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}" />
    <Setter Property="FontSize" Value="{StaticResource TextStyleSmallFontSize}" /> <!-- Note: This does nothing, the ComboBoxes ignore their FontSize settings --><!-- "{ThemeResource ControlContentThemeFontSize}" -->
    <Setter Property="HorizontalAlignment" Value="Left"/>
        <Setter Property="VerticalAlignment" Value="Center"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="DatePicker">
                    <Border x:Name="LayoutRoot"
                         Background="{TemplateBinding Background}"
                         BorderBrush="{TemplateBinding BorderBrush}"
                         BorderThickness="{TemplateBinding BorderThickness}"
                    >
                    <Grid Margin="{TemplateBinding Padding}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <ContentPresenter x:Name="HeaderContentPresenter"
                            FlowDirection="{TemplateBinding FlowDirection}"
                            Content="{TemplateBinding Header}"
                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                            Margin="0"
                            FontWeight="Normal" 
                            Foreground="Red"
                        />
                        <StackPanel Grid.Row="1" Orientation="{TemplateBinding Orientation}">
                            <Border x:Name="FirstPickerHost" Padding="0" Margin="0">
                                <ComboBox x:Name="DayPicker" 
                                    MinHeight="{ThemeResource DatePickerSpacingThemeHeight}"
                                    FontWeight="{TemplateBinding FontWeight}"
                                    FontSize="{TemplateBinding FontSize}"
                                    FontFamily="{TemplateBinding FontFamily}"
                                    RequestedTheme="{TemplateBinding RequestedTheme}"
                                    PickerFlyoutBase.Title="Pick Day"
                                    PlaceholderText="Pick Day"
                                />
                            </Border>
                            <Rectangle x:Name="FirstPickerSpacing"
                                Width="5"
                                Height="{ThemeResource DatePickerSpacingThemeHeight}"
                            />
                            <Border x:Name="SecondPickerHost" Padding="0" Margin="0">
                                <ComboBox x:Name="MonthPicker"
                                    MinHeight="{ThemeResource DatePickerSpacingThemeHeight}"
                                    FontWeight="{TemplateBinding FontWeight}"
                                    FontSize="{TemplateBinding FontSize}"
                                    FontFamily="{TemplateBinding FontFamily}"
                                    RequestedTheme="{TemplateBinding RequestedTheme}"
                                    PickerFlyoutBase.Title="Pick Month"
                                    PlaceholderText="Pick Month"
                                />
                            </Border>
                            <Rectangle x:Name="SecondPickerSpacing"
                                Width="5"
                                Height="{ThemeResource DatePickerSpacingThemeHeight}"
                            />
                            <Border x:Name="ThirdPickerHost" Padding="0" Margin="0">
                                <ComboBox x:Name="YearPicker"
                                    MinHeight="{ThemeResource DatePickerSpacingThemeHeight}"                                                
                                    FontWeight="{TemplateBinding FontWeight}"
                                    FontSize="{TemplateBinding FontSize}"
                                    FontFamily="{TemplateBinding FontFamily}"
                                    RequestedTheme="{TemplateBinding RequestedTheme}"   
                                    PickerFlyoutBase.Title="Pick Year"   
                                    PlaceholderText="Pick Year"
                                />
                            </Border>
                        </StackPanel>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
 </Style>

我从Windows桌面(WinRT)文档中获得了这个ControlTemplate,并从那里对其进行了修改。除了在几个地方不能修改字体颜色外(这就是我之所以做了
RequestedTheme=“Light”
,这是我唯一能使字体颜色变为非白色的方法),它工作得相当好,但这不是问题的重点

我试图纠正的不良行为是,当我点击月、日或年组合框时,当前值不是出现的选择器的焦点。例如,在以下日期选择器中点击“2016”时:

将出现以下选择器窗口:

请注意,如果要选择“2017”,即当前选定值之后的一年,则必须向下滚动至该值。从1916年开始,这意味着100年的滚动时间。这对用户来说是一个巨大的痛苦,显然不是它应该工作的方式

推论问题1:

选择器窗口以模式显示,我似乎找不到直接更改其格式的方法-我的最佳路径是什么?是否有办法将选择器窗口中的文本格式更改为(例如)20点粗体红色文本?实际上,在“选择年份”的顶部有一个短语,但它是白色背景上的白色文本,所以你看不到它。这也是不可取的

推论问题2:

如果不重写ControlTemplate,则日期选择器如下所示:

点击它让我想到:

我似乎也找不到一种方法来修改这个模式呈现的页面,以便 1) 更改其蓝色背景色,因为蓝色与我的应用程序的其他部分不匹配,并且 2) 这样用户就可以看到滚筒式选择器的“列”。在当前状态下,这不是一个可用的UI小部件,因为用户不知道上下滑动会改变值

结论:


谢谢你在这方面给我的任何帮助或指导。我已经完成了从文档中收集到的内容。

我建议您使用WP8.1 SDK中提供的默认日期选择器。但正如你提到的,你面临的问题是你不能改变蓝色。因此,DatePicker在内部使用LoopingSelector,因此基本上需要覆盖默认的LoopingSelector颜色。最好的方法是在App.xaml或任何您定义了所有样式的地方

<SolidColorBrush x:Key="LoopingSelectorSelectionBackgroundThemeBrush" Color="#FFD84E53" />


类似地,您可以覆盖LoopingItems的前景色。您可以从中看到更多详细信息。希望有帮助

谢谢你的提示,我来试试看!我在themeresources.xaml或generic.xaml中的任何地方都没有看到“循环”这个词。。。我应该吗?哇,那把钥匙真管用。我想知道为什么他们没有将其包含在themeresources.xaml或generic.xaml中。不幸的是,链接答案中提到的控件模板仅为UWP,不适用于WinPhone 8.1。所以这里没有骰子。很酷,你能够部分解决这个问题。对于这一点,用户可以看到滚轮式选择器的列。我不完全确定你想在这里实现什么,因为当我们点击日期、月份或年份的任何一列时,我们可以看到相应元素的滚动列表,这是预期的behvior。哦,那么“正常”行为是滚动条不可见?我以前没有在WinPhone上使用过带有日期选择器的应用程序,所以这不是我的期望。但是如果WinPhone就是这样工作的,那么我很乐意接受设备习惯用法,因为这是用户所期望的。