I came across a strange case when I was writing code for saving FilterDescriptors settings for RadDataFilter. The default value for string filter editor is OperatorValueFilterDescriptorBase.UnsetValue, the FilterDescriptor.Value is equal to OperatorValueFilterDescriptorBase.UnsetValue (FilterDescriptor .Value == OperatorValueFilterDescriptorBase.UnsetValue). When I save and read this value from isolated storage is not equal to OperatorValueFilterDescriptorBase.UnsetValue. See example bellow.
The following example is completely useless but it shows error.
MainWindow.xaml:
MainWindow.xaml.cs
For one TextBox I save or read data to isolated storage.
UnsetValuePropertyProvider.cs:
UnsetValueProxy.cs:
In ProvideValue method I pass to proxy object OperatorValueFilterDescriptorBase.UnsetValue value and in RestoreValue unsetValueProxy.Value is not equal to OperatorValueFilterDescriptorBase.UnsetValue and it should be. See also locals tab in debug mode (example.png).
The following example is completely useless but it shows error.
MainWindow.xaml:
<
Window
x:Class
=
"TestTelerikWpfApp.MainWindow"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
xmlns:local
=
"clr-namespace:TestTelerikWpfApp"
Title
=
"MainWindow"
Height
=
"300"
>
<
Window.Resources
>
</
Window.Resources
>
<
StackPanel
>
<
TextBox
telerik:PersistenceManager.StorageId
=
"textBox"
/>
<
StackPanel
Orientation
=
"Vertical"
>
<
telerik:RadButton
Content
=
"Save"
Click
=
"SaveButton_Click"
/>
<
telerik:RadButton
Content
=
"Read"
Click
=
"ReadButton_Click"
/>
</
StackPanel
>
</
StackPanel
>
</
Window
>
MainWindow.xaml.cs
namespace
TestTelerikWpfApp
{
using
System.Windows;
using
System.Windows.Controls;
using
Telerik.Windows.Persistence.Services;
using
Telerik.Windows.Persistence.Storage;
public
partial
class
MainWindow : Window
{
private
IsolatedStorageProvider isoProvider;
public
MainWindow()
{
InitializeComponent();
ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(
typeof
(TextBox),
new
UnsetValuePropertyProvider());
isoProvider =
new
IsolatedStorageProvider();
}
private
void
SaveButton_Click(
object
sender, RoutedEventArgs e)
{
isoProvider.SaveToStorage();
}
private
void
ReadButton_Click(
object
sender, RoutedEventArgs e)
{
isoProvider.LoadFromStorage();
}
}
}
For one TextBox I save or read data to isolated storage.
UnsetValuePropertyProvider.cs:
namespace
TestTelerikWpfApp
{
using
Telerik.Windows.Data;
using
Telerik.Windows.Persistence.Services;
class
UnsetValuePropertyProvider : ICustomPropertyProvider
{
public
CustomPropertyInfo[] GetCustomProperties()
{
return
new
CustomPropertyInfo[]
{
new
CustomPropertyInfo(
"UnsetValue"
,
typeof
(UnsetValueProxy))
};
}
public
void
InitializeObject(
object
context)
{
}
public
object
InitializeValue(CustomPropertyInfo customPropertyInfo,
object
context)
{
return
null
;
}
public
object
ProvideValue(CustomPropertyInfo customPropertyInfo,
object
context)
{
return
new
UnsetValueProxy() { Value = OperatorValueFilterDescriptorBase.UnsetValue };
}
public
void
RestoreValue(CustomPropertyInfo customPropertyInfo,
object
context,
object
value)
{
var unsetValueProxy = value
as
UnsetValueProxy;
var isUnsetValueSame = unsetValueProxy.Value == OperatorValueFilterDescriptorBase.UnsetValue;
// isUnsetValueSame = false !!!
}
}
}
UnsetValueProxy.cs:
namespace
TestTelerikWpfApp
{
class
UnsetValueProxy
{
public
object
Value {
get
;
set
; }
}
}
In ProvideValue method I pass to proxy object OperatorValueFilterDescriptorBase.UnsetValue value and in RestoreValue unsetValueProxy.Value is not equal to OperatorValueFilterDescriptorBase.UnsetValue and it should be. See also locals tab in debug mode (example.png).