private DateTime? GetKeyFromDataSourceItem(object value)
{
if (_dummyItem == null)
{
_dummyItem = new FrameworkElement();
}
Binding bind = new Binding();
if (DataSourceDatePath != null)//TODO:bug#1662127
{
bind.Path = DataSourceDatePath;
}
bind.XPath = DataSourceDateXPath;
bind.Source = value;
_dummyItem.SetBinding(FrameworkElement.TagProperty, bind);
object tag = _dummyItem.Tag;
if (_dummyItem.Tag is XmlAttribute)
{
tag = ((XmlAttribute)_dummyItem.Tag).Value;
}
else if (_dummyItem.Tag is XmlElement)
{
tag = ((XmlElement)_dummyItem.Tag).InnerText;
}
DateTime? key = new DateTime?();
if (tag is string)
{
try
{
key = DateTime.Parse((string)tag, Language.GetSpecificCulture().DateTimeFormat);
}
catch (FormatException)
{
}
}
else if (tag is DateTime)
{
key = (DateTime)_dummyItem.Tag;
}
BindingOperations.ClearBinding(_dummyItem, FrameworkElement.TagProperty);
return key;
}