Xaml:
<StackPanel x:Name="sproot" Background="White">
<StackPanel.Resources>
<my:Converter x:Key="myConverter"></my:Converter>
</StackPanel.Resources>
<TextBlock x:Name="tbkDate" Width="180"
Margin="5" FontSize="15" Height="30"
Text="{Binding Date,Mode=TwoWay,Converter={StaticResource myConverter}}"></TextBlock>
<sdk:Calendar Height="169" Name="calendar1" Width="230" />
</StackPanel>
Xaml.cs:
Book book = new Book();
public MainPage()
{
InitializeComponent();
calendar1.SelectedDatesChanged += new EventHandler<SelectionChangedEventArgs>(calendar1_SelectedDatesChanged);
book.Date = DateTime.Now.ToLongDateString();
tbkDate.DataContext = book;
}
void calendar1_SelectedDatesChanged(object sender, SelectionChangedEventArgs e)
{
book.Date = calendar1.SelectedDate.ToString();
}
Book.cs:
public class Book : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private string _Title;
public string Date
{
get { return _Title; }
set
{
_Title = value;
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs("Date"));
}
}
}
}
Converter.cs:
public class Converter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return DateTime.Parse(value.ToString()).ToString("yyyy年MM月dd日");
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}