如何将此属性转换为依赖属性?关于每个人都只是说“不要在依赖属性中使用逻辑”并且没有为此提出补救措施:
public DateTime? SelectedDateGeorgian
{
get
{
//choose a control based on this "user control" current mode
//and return its value
}
set
{
//choose a control based on this "user control" current mode
// and set its property after some manipulations on the value
}
}
我想把它转换成这个:
public static readonly DependencyProperty SelectedDateGeorgianProperty =
DependencyProperty.Register("SelectedDateGeorgian", typeof(DateTime?), typeof(MyDatePicker), new PropertyMetadata(default(DateTime?)));
public DateTime? SelectedDateGeorgian
{
get
{
//Its prohobited to do something here ! So what should I do ?
//How should I select a control and return its value here ?
//I can't have a simple backing variable because I should do some conversion here
return (DateTime?)GetValue(SelectedDateGeorgianProperty);
}
set
{
//I want to convert received value here and
// and after that update some UI properties in this user control
SetValue(SelectedDateMiladiProperty, value);
}
}
我想转换将要写入此依赖属性的值并更新 UIElements。
而且我还想从 UIElement 转换一个值,并在要读取它时返回转换后的值。
所以你看我不能有一个简单的支持变量。
请有人给我一个模式来实现这个。
感谢您的关注。