0
    <toolkit:DatePicker Value="2/28/2010" />

I need show only month and year in my date picker (WP8). I've tried to do this in such way, but it was not working:

    <toolkit:DatePicker Value="{Binding DateValue}" ValueStringFormat="{}{0:MM-yyyy}" />

I need it for DatePickerPage too.

CatCap
  • 240
  • 5
  • 19

5 Answers5

2

You cannot implement this by adding xaml string format. For implement such functionality you need to edit the toolkit code. For that you can download the open source code from CodePlex. After downloading the project find the Date Picker class and edit the relevant methods to remove the date. recompile the source in release mode and you can use that new dll.

Rakesh R Nair
  • 1,736
  • 2
  • 12
  • 30
1

If you don't want to copy the page from Codeplex, you can extend the page and override the GetSelectorsOrderedByCulturePattern method to change the day selector's visibility. In the example below I've fixed it to month then year, which you may not want in your version. Also I'm accessing controls by name, so take care with future updates to WindowsPhone Toolkit.

<toolkit:DatePickerPage
    x:Class="MyApp.MonthYearPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    mc:Ignorable="d"
    shell:SystemTray.IsVisible="True">

</toolkit:DatePickerPage>

And

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Phone.Controls.Primitives;
using System.Diagnostics;
using System.Windows.Media;

namespace MyApp
{
    public partial class MonthYearPage : DatePickerPage
    {
        public MonthYearPage()
        {
            InitializeComponent();
        }

        protected override IEnumerable<LoopingSelector> GetSelectorsOrderedByCulturePattern()
        {
            var PrimarySelector = ((Grid)Content).FindName("PrimarySelector") as LoopingSelector;
            var SecondarySelector = ((Grid)Content).FindName("SecondarySelector") as LoopingSelector;
            var TertiarySelector = ((Grid)Content).FindName("TretiarySelector") as LoopingSelector;

            var selectors = GetSelectorsOrderedByCulturePattern(
                "DMY",
                new char[] { 'Y', 'M', 'D' },
                new LoopingSelector[] { PrimarySelector, SecondarySelector, TertiarySelector });

            // Passing "DMY" in on the previous line makes sure the day selector
            // is the first one in the enumeration. You may want to change the order
            // of 'M' and 'Y' in that string for your needs or depending on region.
            selectors.First<LoopingSelector>().Visibility = Visibility.Collapsed;
            return selectors;
        }
    }
}
0

{}{0:"Y","y"} have a good day :D ( information here --> http://msdn.microsoft.com/en-us/library/az4se3k1%28v=VS.95%29.aspx)

MatDev8
  • 976
  • 5
  • 18
  • Such code is not compiling. :( – CatCap Sep 12 '13 at 11:55
  • sorry try ValueStringFormat="{}{0:Y,y}" or ValueStringFormat="{}{0:Y:y}"...i can't test in my pc at this moment sorry.If it doesn't work, i will test it tonight :) – MatDev8 Sep 12 '13 at 12:03
  • such code works only for DatePicker, but i need only two columpns on DatePickerPage. – CatCap Sep 12 '13 at 12:03
  • 1
    hummm i think you can't remove column with toolkit but you can see this link http://www.geekchamp.com/articles/wp7-loopingselector-in-depth--part1-visual-structure-and-api. – MatDev8 Sep 12 '13 at 12:06
0

This should help to format the DateTimeButton content to display month and year only: <toolkit:DatePicker x:Name="datePicker" ValueStringFormat="{}{0:y}"/>

0

Format exhibited depending on the location but this can be avoided by writing this:

<toolkit:DatePicker 
                    Value="{Binding DateCard, Mode=TwoWay}" 
                    ValueStringFormat="{}{0:MM'/'yy}" />

And you will be happy!(dd'/'MM'/'yyy)