I have implemented a CustomePropertyProvider for my TileView and I am attepting to save and restore the positions of the tiles at the moment. I can save the Positions and write these to isolated storage. However when I read these back the manage does not seem to be firing the RestoreValue Method on my class, but it did call the ProvideValue Method when saving.
Class Implementing ICustomPropertyProvider
Code for Saving:-
Code for Loading
This is called from the Constrctor of the userControl
Any help would be appreciated as I get no errors.Thanks
Greg
Class Implementing ICustomPropertyProvider
public
class
TileViewCustomPropertyProvider : ICustomPropertyProvider
{
public
CustomPropertyInfo[] GetCustomProperties()
{
return
new
CustomPropertyInfo[]
{
new
CustomPropertyInfo(
"Layout"
,
typeof
(Dictionary<
string
,
int
>))
};
}
public
void
InitializeObject(
object
context)
{
}
public
object
InitializeValue(CustomPropertyInfo customPropertyInfo,
object
context)
{
return
null
;
}
public
object
ProvideValue(CustomPropertyInfo customPropertyInfo,
object
context)
{
RadTileView tileView = context
as
RadTileView;
if
(customPropertyInfo.Name ==
"Layout"
)
{
Dictionary<
string
,
int
> positions =
new
Dictionary<
string
,
int
>();
foreach
(RadTileViewItem tile
in
tileView.Items)
{
positions.Add(tile.Name, tile.Position);
}
return
positions;
}
return
null
;
}
public
void
RestoreValue(CustomPropertyInfo customPropertyInfo,
object
context,
object
value)
{
RadTileView tileView = context
as
RadTileView;
Dictionary<
string
,
int
> positions = value
as
Dictionary<
string
,
int
>;
if
(customPropertyInfo.Name ==
"layout"
)
{
foreach
(RadTileViewItem tile
in
tileView.Items)
{
int
position = -1;
if
(positions.TryGetValue(tile.Name,
out
position))
tile.Position = position;
}
}
}
Code for Saving:-
PersistenceManager manager =
new
PersistenceManager();
stream = manager.Save(
this
.rtvDashboard);
using
(var store = IsolatedStorageFile.GetUserStoreForApplication())
{
var fs = store.CreateFile(
"dashboardLayout"
);
byte
[] bytes =
new
byte
[stream.Length];
fs.Write(bytes, 0, (
int
)stream.Length);
}
Code for Loading
private
void
LoadSettings()
{
PersistenceManager manager =
new
PersistenceManager();
using
(var store = IsolatedStorageFile.GetUserStoreForApplication())
{
if
(store.FileExists(
"dashboardlayout"
))
{
var fs = store.OpenFile(
"dashboardLayout"
, FileMode.Open);
fs.Position = 0L;
manager.Load(
this
.rtvDashboard, fs);
}
}
}
public
MainPage()
{
InitializeComponent();
this
.btnSaveLayout.Click +=
new
RoutedEventHandler(btnSaveLayout_Click);
ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(
typeof
(RadTileView),
new
TileViewCustomPropertyProvider());
LoadSettings();
}
Any help would be appreciated as I get no errors.Thanks
Greg