我正在建立一个简单的
用户控件
双重日期选择器
,它定义了
关联属性
,
选定日期
:
DoubleDatePicker.xaml文件
:
<UserControl x:Class="TestWpfDoubleDatePicker.DoubleDatePicker"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit">
<StackPanel x:Name="LayoutRoot" Background="White">
<toolkit:DatePicker x:Name="DateInput" SelectedDate="{Binding SelectedDate,Mode=TwoWay}" Margin="5,0,5,0" />
<TextBlock Text="{Binding SelectedDate}" />
<toolkit:DatePicker SelectedDate="{Binding SelectedDate,Mode=TwoWay}" Margin="5,0,5,0" />
</StackPanel>
DoubleDatePicker.xaml.cs
:
using System;
using System.Windows;
using System.Windows.Controls;
namespace TestWpfDoubleDatePicker
{
public partial class DoubleDatePicker : UserControl
{
public static readonly DependencyProperty SelectedDateProperty =
DependencyProperty.Register("SelectedDate", typeof(DateTime), typeof(DoubleDatePicker), null);
public DateTime SelectedDate
{
get { return (DateTime)this.GetValue(SelectedDateProperty); }
set { this.SetValue(SelectedDateProperty, value); }
}
public DoubleDatePicker()
{
this.InitializeComponent();
this.DataContext = this;
}
}
}
我希望能把这本书装订起来
选定日期
但事情看起来并不是那么简单。
控件
:
主窗口.xaml
:
<Window x:Class="TestWpfDoubleDatePicker.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:TestWpfDoubleDatePicker"
Title="MainWindow" Height="350" Width="525">
<StackPanel x:Name="LayoutRoot" Background="White">
<local:DoubleDatePicker x:Name="ddp" SelectedDate="{Binding SelectedDate}" />
<Button Content="Update" Click="Button_Click" />
<TextBlock Text="{Binding SelectedDate}" />
</StackPanel>
和
主窗口.xaml.cs
:
using System;
using System.Windows;
namespace TestWpfDoubleDatePicker
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public static readonly DependencyProperty SelectedDateProperty =
DependencyProperty.Register("SelectedDate", typeof(DateTime), typeof(MainWindow), null);
public DateTime SelectedDate
{
get { return (DateTime)this.GetValue(SelectedDateProperty); }
set { this.SetValue(SelectedDateProperty, value); }
}
public MainWindow()
{
InitializeComponent();
this.DataContext = this;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.SelectedDate = this.ddp.SelectedDate;
}
}
}
内部
双重日期选择器
属性在使用这两个属性中的任何一个进行更改时进行更新
日期选择器
控件
的
双重日期选择器
但是,在外面
控件
的
不是自动更新的,也是获取
选定日期
财产
双重日期选择器
按钮
.
我做错什么了?
提前谢谢你的帮助。