Hi all,
can somebody look at the code and tell me what's i am doing wrong.
My Dashboard XML
<UserControl x:Class="SimpleModule.Views.DashboardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:cal="http://www.codeplex.com/prism"
d:DesignHeight="600" d:DesignWidth="900">
<UserControl.Resources>
<DataTemplate x:Key="ItemTemplate">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
<DataTemplate x:Key="ContentTemplate">
<ContentControl cal:RegionManager.RegionName="{Binding Name}">
</ContentControl>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" Height="500">
<Grid.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True"></Setter>
</Style>
<Style TargetType="telerik:RadTileView">
<Setter Property="Margin" Value="10" />
<Setter Property="MaximizeMode" Value="Zero"/>
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="PreservePositionWhenMaximized" Value="True" />
<Setter Property="TileStateChangeTrigger" Value="SingleClick" />
<Setter Property="IsAutoScrollingEnabled" Value="True" />
<Setter Property="IsDockingEnabled" Value="True" />
<Setter Property="telerik:RadDragAndDropManager.AllowDrop" Value="True"/>
<Setter Property="ContentTemplate" Value="{StaticResource ContentTemplate}" />
<Setter Property="ItemTemplate" Value="{StaticResource ItemTemplate}" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="597*" />
<ColumnDefinition Width="303*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="72*" />
<RowDefinition Height="405" />
<RowDefinition Height="23*" />
</Grid.RowDefinitions>
<TextBlock Height="47" HorizontalAlignment="Left" Margin="47,25,0,0" Text="My Dashboard" VerticalAlignment="Top" FontSize="28" FontFamily="Lucida Sans Unicode" Width="245" />
<TextBlock FontFamily="Lucida Sans Unicode" FontSize="24" Height="33" HorizontalAlignment="Left" Margin="18,25,0,0" Text="Drag Drop Elements" VerticalAlignment="Top" Width="245" Grid.Column="1" />
<ListBox x:Name="ApplicationList" ItemsSource="{Binding AllWidgets}" SelectedItem="{Binding SelectedWidget,Mode=TwoWay}" DisplayMemberPath="Name" Padding="20" Grid.Column="1" Grid.Row="1" Height="326" HorizontalAlignment="Left" Margin="18,10,0,0" VerticalAlignment="Top" Width="225">
<ListBox.BorderBrush>
<LinearGradientBrush>
<GradientStop Color="#FFA3AEB9" Offset="0" />
<GradientStop Color="#FF8399A9" Offset="0.375" />
<GradientStop Color="#FF718597" Offset="0.529" />
<GradientStop Color="#FF617584" Offset="1" />
</LinearGradientBrush>
</ListBox.BorderBrush>
</ListBox>
<telerik:RadTileView Name="rtvViews" ItemsSource="{Binding ViewItems}" Grid.Row="1"/>
<Button Content="Save" Grid.Column="1" Grid.Row="1" Height="53" HorizontalAlignment="Left" Margin="18,342,0,0" VerticalAlignment="Top" Width="100" FontSize="24" Click="button1_Click" />
<Button Content="Load" FontSize="24" Height="53" HorizontalAlignment="Left" Margin="143,342,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1" Grid.Row="1" Click="OnLoad" />
<ComboBox ItemsSource="{Binding MyLayout}" SelectedItem="{Binding SelectedLayout,Mode=TwoWay}" HorizontalAlignment="Left" Margin="467,40,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Show Student" Command="{Binding StudentCommand}" HorizontalAlignment="Left" Margin="309,30,0,0" VerticalAlignment="Top" Height="30" Width="92" />
</Grid>
</UserControl>
Code behind of XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.ServiceLocation;
using SimpleModule.ViewModels;
using System.Collections;
using School.Web;
using Telerik.Windows.DragDrop;
using Telerik.Windows.Persistence;
using Telerik.Windows.Persistence.SerializationMetadata;
using Telerik.Windows.Controls.DragDrop;
using System.Collections.ObjectModel;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;
using System.Reflection;
using Telerik.Windows.Persistence.Services;
using Telerik.Windows.Controls;
using SimpleModule.Helpers;
namespace SimpleModule.Views
{
public partial class DashboardView : UserControl
{
System.IO.Stream stream;
DashboardViewModel vm;
public DashboardView()
{
InitializeComponent();
vm = ServiceLocator.Current.GetInstance<DashboardViewModel>();
this.DataContext = vm;
RadDragAndDropManager.AddDragQueryHandler(this, vm.OnDragQuery);
RadDragAndDropManager.AddDropQueryHandler(this, vm.OnDropQuery);
RadDragAndDropManager.AddDropInfoHandler(this, vm.OnDropInfo);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PersistenceManager manager = new PersistenceManager();
stream = manager.Save(rtvViews);
vm.SaveClicked(stream);
}
private void OnLoad(object sender, System.Windows.RoutedEventArgs e)
{
LoadStream();
}
private void LoadStream()
{
this.stream.Position = 0L;
this.stream = vm.LoadClicked();
if (this.stream != null)
{
PersistenceManager manager = new PersistenceManager();
manager.Load(this.rtvViews, this.stream);
}
}
}
}
My ViewModel
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Commands;
using System.Linq;
using SimpleModule.Views;
using School.Web;
using System.Collections.ObjectModel;
using System.ServiceModel.DomainServices.Client;
using System.Collections.Generic;
using System.IO;
using Telerik.Windows.Controls.DragDrop;
using System.Reflection;
using SimpleModule.Helpers;
namespace SimpleModule.ViewModels
{
public class DashboardViewModel : ViewModelBase
{
#region Events
public event EventHandler DataLoaded;
#endregion
#region Commands
public ICommand StudentCommand { get; set; }
#endregion
#region Properties
private ObservableCollection<WidgetDTO> _allWidgets;
public ObservableCollection<WidgetDTO> AllWidgets
{
get { return _allWidgets; }
set { _allWidgets = value; OnPropertyChanged("AllWidgets"); }
}
private WidgetDTO _selectedWidget;
public WidgetDTO SelectedWidget
{
get { return _selectedWidget; }
set
{
_selectedWidget = value;
OnPropertyChanged("SelectedWidget");
}
}
public List<DashboardDTO> DashboardLayouts { get; set; }
private ObservableCollection<string> _myLayOut;
public ObservableCollection<string> MyLayout
{
get { return _myLayOut; }
set { _myLayOut = value; OnPropertyChanged("MyLayout"); }
}
private string _selectedLayout;
public string SelectedLayout
{
get { return _selectedLayout; }
set
{
_selectedLayout = value;
if (value == "6 Cell")
{
ViewItems = _viewItems6;
}
else
{
ViewItems = _viewItems9;
}
DashboardDTO dto = DashboardLayouts.Where(c => c.LayoutName == value).FirstOrDefault();
if (dto == null)
{
dto = new DashboardDTO();
dto.LayoutName = value;
DashboardLayouts.Add(dto);
Context.DashboardDTOs.Add(dto);
}
OnPropertyChanged("SelectedLayout");
}
}
private ObservableCollection<TileViewModel> _viewItems6;
private ObservableCollection<TileViewModel> _viewItems9;
private ObservableCollection<TileViewModel> _viewItems;
public ObservableCollection<TileViewModel> ViewItems
{
get { return _viewItems; }
set { _viewItems = value; OnPropertyChanged("ViewItems"); }
}
#endregion
public DashboardViewModel(IUnityContainer container, IEventAggregator eventAggregator, IRegionManager regionManager)
: base(regionManager, container)
{
StudentCommand = new DelegateCommand(StudentClicked);
Context = new NetflixDomain();
LoadWidgets();
LoadLayouts();
}
#region Methods
private void LoadWidgets()
{
var query = Context.GetWidgetsQuery();
LoadOperation<WidgetDTO> operation = Context.Load<WidgetDTO>(query);
operation.Completed += new EventHandler(operation_Completed);
}
void operation_Completed(object sender, EventArgs e)
{
LoadOperation<WidgetDTO> operation = (LoadOperation<WidgetDTO>)sender;
if (operation.Entities != null)
{
AllWidgets = new ObservableCollection<WidgetDTO>(operation.Entities);
}
}
private void LoadLayouts()
{
var query = Context.GetDashboardQuery();
LoadOperation<DashboardDTO> operation = Context.Load<DashboardDTO>(query);
operation.Completed += new EventHandler(layoutOperation_Completed);
}
void layoutOperation_Completed(object sender, EventArgs e)
{
LoadOperation<DashboardDTO> operation = (LoadOperation<DashboardDTO>)sender;
if (operation.Entities != null)
{
DashboardLayouts = operation.Entities.ToList();
MyLayout = new ObservableCollection<string>();
MyLayout.Add("6 Cell");
MyLayout.Add("9 Cell");
TileViewModel model;
_viewItems6 = new ObservableCollection<TileViewModel>();
for (int i = 1; i <= 6; i++)
{
model = new TileViewModel();
model.Name = "Cell6" + i.ToString();
_viewItems6.Add(model);
RegionManager.Regions.Add(model.Name, new SingleActiveRegion());
}
_viewItems9 = new ObservableCollection<TileViewModel>();
for (int i = 1; i <= 9; i++)
{
model = new TileViewModel();
model.Name = "Cell9" + i.ToString();
_viewItems9.Add(model);
RegionManager.Regions.Add(model.Name, new SingleActiveRegion());
}
SelectedLayout = MyLayout.FirstOrDefault();
if (DataLoaded != null)
{
DataLoaded.Invoke(sender, null);
}
}
}
public void SaveClicked(Stream data)
{
MemoryStream ms = new MemoryStream();
data.CopyTo(ms);
DashboardDTO dto = DashboardLayouts.Where(c => c.LayoutName == SelectedLayout).FirstOrDefault();
dto.DashboardLayout = ms.ToArray();
Context.SubmitChanges(Submit_Completed, null);
}
private void Submit_Completed(SubmitOperation operation)
{
if (operation.HasError)
{
MessageBox.Show(operation.Error.Message);
}
else
{
MessageBox.Show("Data saved successfully");
}
}
public Stream LoadClicked()
{
DashboardDTO dto = DashboardLayouts.Where(c => c.LayoutName == SelectedLayout).FirstOrDefault();
Stream str = new MemoryStream(dto.DashboardLayout);
return str;
}
private void StudentClicked()
{
StudentViewModel vm = Container.Resolve<StudentViewModel>();
object pview = RegionManager.Regions["MainRegion"].Views.FirstOrDefault(region => region.GetType().Equals(typeof(DashboardView)));
vm.ReturnView = pview;
if (pview != null)
{
RegionManager.Regions["MainRegion"].Remove(pview);
}
StudentView view = Container.Resolve<StudentView>();
vm.MyView = view;
view.DataContext = vm;
RegionManager.AddToRegion("MainRegion", view);
RegionManager.Regions["MainRegion"].Activate(view);
}
#region DragDrop functionality
public void OnDragQuery(object sender, DragDropQueryEventArgs e)
{
if (e.Options.Status == DragStatus.DragQuery && SelectedWidget != null)
{
e.Options.Payload = SelectedWidget;
ContentControl cue = new ContentControl();
cue.Content = SelectedWidget;
e.Options.DragCue = cue;
e.Options.ArrowCue = RadDragAndDropManager.GenerateVisualCue();
}
e.QueryResult = true;
}
public void OnDropQuery(object sender, DragDropQueryEventArgs e)
{
e.QueryResult = true;
}
public void OnDropInfo(object sender, DragDropEventArgs e)
{
if (e.Options.Status == DragStatus.DropComplete)
{
WidgetDTO widget = e.Options.Payload as WidgetDTO;
TileViewModel model = (e.OriginalSource as FrameworkElement).DataContext as TileViewModel;
Assembly assembly = Assembly.GetExecutingAssembly();
Type wType = assembly.GetType("SimpleModule.MyWidgets." + widget.Name);
RegionManager.RegisterViewWithRegion(model.Name, wType);
string w1 = widget.Name + ".xaml";
RegionManager.AddToRegion(model.Name, w1);
RegionManager.Regions[model.Name].Activate(w1);
}
}
#endregion
#endregion
}
}
and I have a directory of of Widgets in the SimpleModule.MyWidgets that are simply the user control with a hardcoded label.
...
I want to make it persistence by saving the stream in the database and then getting it back from there and applying it to the GUI.
I am stick here and didn't know what's i am doing wrong here..
can somebody look at the code and tell me what's i am doing wrong.
My Dashboard XML
<UserControl x:Class="SimpleModule.Views.DashboardView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"
xmlns:cal="http://www.codeplex.com/prism"
d:DesignHeight="600" d:DesignWidth="900">
<UserControl.Resources>
<DataTemplate x:Key="ItemTemplate">
<TextBlock Text="{Binding Name}" />
</DataTemplate>
<DataTemplate x:Key="ContentTemplate">
<ContentControl cal:RegionManager.RegionName="{Binding Name}">
</ContentControl>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White" Height="500">
<Grid.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="telerik:RadDragAndDropManager.AllowDrag" Value="True"></Setter>
</Style>
<Style TargetType="telerik:RadTileView">
<Setter Property="Margin" Value="10" />
<Setter Property="MaximizeMode" Value="Zero"/>
<Setter Property="BorderBrush" Value="Black" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="PreservePositionWhenMaximized" Value="True" />
<Setter Property="TileStateChangeTrigger" Value="SingleClick" />
<Setter Property="IsAutoScrollingEnabled" Value="True" />
<Setter Property="IsDockingEnabled" Value="True" />
<Setter Property="telerik:RadDragAndDropManager.AllowDrop" Value="True"/>
<Setter Property="ContentTemplate" Value="{StaticResource ContentTemplate}" />
<Setter Property="ItemTemplate" Value="{StaticResource ItemTemplate}" />
</Style>
</Grid.Resources>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="597*" />
<ColumnDefinition Width="303*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="72*" />
<RowDefinition Height="405" />
<RowDefinition Height="23*" />
</Grid.RowDefinitions>
<TextBlock Height="47" HorizontalAlignment="Left" Margin="47,25,0,0" Text="My Dashboard" VerticalAlignment="Top" FontSize="28" FontFamily="Lucida Sans Unicode" Width="245" />
<TextBlock FontFamily="Lucida Sans Unicode" FontSize="24" Height="33" HorizontalAlignment="Left" Margin="18,25,0,0" Text="Drag Drop Elements" VerticalAlignment="Top" Width="245" Grid.Column="1" />
<ListBox x:Name="ApplicationList" ItemsSource="{Binding AllWidgets}" SelectedItem="{Binding SelectedWidget,Mode=TwoWay}" DisplayMemberPath="Name" Padding="20" Grid.Column="1" Grid.Row="1" Height="326" HorizontalAlignment="Left" Margin="18,10,0,0" VerticalAlignment="Top" Width="225">
<ListBox.BorderBrush>
<LinearGradientBrush>
<GradientStop Color="#FFA3AEB9" Offset="0" />
<GradientStop Color="#FF8399A9" Offset="0.375" />
<GradientStop Color="#FF718597" Offset="0.529" />
<GradientStop Color="#FF617584" Offset="1" />
</LinearGradientBrush>
</ListBox.BorderBrush>
</ListBox>
<telerik:RadTileView Name="rtvViews" ItemsSource="{Binding ViewItems}" Grid.Row="1"/>
<Button Content="Save" Grid.Column="1" Grid.Row="1" Height="53" HorizontalAlignment="Left" Margin="18,342,0,0" VerticalAlignment="Top" Width="100" FontSize="24" Click="button1_Click" />
<Button Content="Load" FontSize="24" Height="53" HorizontalAlignment="Left" Margin="143,342,0,0" VerticalAlignment="Top" Width="100" Grid.Column="1" Grid.Row="1" Click="OnLoad" />
<ComboBox ItemsSource="{Binding MyLayout}" SelectedItem="{Binding SelectedLayout,Mode=TwoWay}" HorizontalAlignment="Left" Margin="467,40,0,0" VerticalAlignment="Top" Width="120"/>
<Button Content="Show Student" Command="{Binding StudentCommand}" HorizontalAlignment="Left" Margin="309,30,0,0" VerticalAlignment="Top" Height="30" Width="92" />
</Grid>
</UserControl>
Code behind of XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.ServiceLocation;
using SimpleModule.ViewModels;
using System.Collections;
using School.Web;
using Telerik.Windows.DragDrop;
using Telerik.Windows.Persistence;
using Telerik.Windows.Persistence.SerializationMetadata;
using Telerik.Windows.Controls.DragDrop;
using System.Collections.ObjectModel;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Regions;
using System.Reflection;
using Telerik.Windows.Persistence.Services;
using Telerik.Windows.Controls;
using SimpleModule.Helpers;
namespace SimpleModule.Views
{
public partial class DashboardView : UserControl
{
System.IO.Stream stream;
DashboardViewModel vm;
public DashboardView()
{
InitializeComponent();
vm = ServiceLocator.Current.GetInstance<DashboardViewModel>();
this.DataContext = vm;
RadDragAndDropManager.AddDragQueryHandler(this, vm.OnDragQuery);
RadDragAndDropManager.AddDropQueryHandler(this, vm.OnDropQuery);
RadDragAndDropManager.AddDropInfoHandler(this, vm.OnDropInfo);
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PersistenceManager manager = new PersistenceManager();
stream = manager.Save(rtvViews);
vm.SaveClicked(stream);
}
private void OnLoad(object sender, System.Windows.RoutedEventArgs e)
{
LoadStream();
}
private void LoadStream()
{
this.stream.Position = 0L;
this.stream = vm.LoadClicked();
if (this.stream != null)
{
PersistenceManager manager = new PersistenceManager();
manager.Load(this.rtvViews, this.stream);
}
}
}
}
My ViewModel
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Microsoft.Practices.Prism.Commands;
using System.Linq;
using SimpleModule.Views;
using School.Web;
using System.Collections.ObjectModel;
using System.ServiceModel.DomainServices.Client;
using System.Collections.Generic;
using System.IO;
using Telerik.Windows.Controls.DragDrop;
using System.Reflection;
using SimpleModule.Helpers;
namespace SimpleModule.ViewModels
{
public class DashboardViewModel : ViewModelBase
{
#region Events
public event EventHandler DataLoaded;
#endregion
#region Commands
public ICommand StudentCommand { get; set; }
#endregion
#region Properties
private ObservableCollection<WidgetDTO> _allWidgets;
public ObservableCollection<WidgetDTO> AllWidgets
{
get { return _allWidgets; }
set { _allWidgets = value; OnPropertyChanged("AllWidgets"); }
}
private WidgetDTO _selectedWidget;
public WidgetDTO SelectedWidget
{
get { return _selectedWidget; }
set
{
_selectedWidget = value;
OnPropertyChanged("SelectedWidget");
}
}
public List<DashboardDTO> DashboardLayouts { get; set; }
private ObservableCollection<string> _myLayOut;
public ObservableCollection<string> MyLayout
{
get { return _myLayOut; }
set { _myLayOut = value; OnPropertyChanged("MyLayout"); }
}
private string _selectedLayout;
public string SelectedLayout
{
get { return _selectedLayout; }
set
{
_selectedLayout = value;
if (value == "6 Cell")
{
ViewItems = _viewItems6;
}
else
{
ViewItems = _viewItems9;
}
DashboardDTO dto = DashboardLayouts.Where(c => c.LayoutName == value).FirstOrDefault();
if (dto == null)
{
dto = new DashboardDTO();
dto.LayoutName = value;
DashboardLayouts.Add(dto);
Context.DashboardDTOs.Add(dto);
}
OnPropertyChanged("SelectedLayout");
}
}
private ObservableCollection<TileViewModel> _viewItems6;
private ObservableCollection<TileViewModel> _viewItems9;
private ObservableCollection<TileViewModel> _viewItems;
public ObservableCollection<TileViewModel> ViewItems
{
get { return _viewItems; }
set { _viewItems = value; OnPropertyChanged("ViewItems"); }
}
#endregion
public DashboardViewModel(IUnityContainer container, IEventAggregator eventAggregator, IRegionManager regionManager)
: base(regionManager, container)
{
StudentCommand = new DelegateCommand(StudentClicked);
Context = new NetflixDomain();
LoadWidgets();
LoadLayouts();
}
#region Methods
private void LoadWidgets()
{
var query = Context.GetWidgetsQuery();
LoadOperation<WidgetDTO> operation = Context.Load<WidgetDTO>(query);
operation.Completed += new EventHandler(operation_Completed);
}
void operation_Completed(object sender, EventArgs e)
{
LoadOperation<WidgetDTO> operation = (LoadOperation<WidgetDTO>)sender;
if (operation.Entities != null)
{
AllWidgets = new ObservableCollection<WidgetDTO>(operation.Entities);
}
}
private void LoadLayouts()
{
var query = Context.GetDashboardQuery();
LoadOperation<DashboardDTO> operation = Context.Load<DashboardDTO>(query);
operation.Completed += new EventHandler(layoutOperation_Completed);
}
void layoutOperation_Completed(object sender, EventArgs e)
{
LoadOperation<DashboardDTO> operation = (LoadOperation<DashboardDTO>)sender;
if (operation.Entities != null)
{
DashboardLayouts = operation.Entities.ToList();
MyLayout = new ObservableCollection<string>();
MyLayout.Add("6 Cell");
MyLayout.Add("9 Cell");
TileViewModel model;
_viewItems6 = new ObservableCollection<TileViewModel>();
for (int i = 1; i <= 6; i++)
{
model = new TileViewModel();
model.Name = "Cell6" + i.ToString();
_viewItems6.Add(model);
RegionManager.Regions.Add(model.Name, new SingleActiveRegion());
}
_viewItems9 = new ObservableCollection<TileViewModel>();
for (int i = 1; i <= 9; i++)
{
model = new TileViewModel();
model.Name = "Cell9" + i.ToString();
_viewItems9.Add(model);
RegionManager.Regions.Add(model.Name, new SingleActiveRegion());
}
SelectedLayout = MyLayout.FirstOrDefault();
if (DataLoaded != null)
{
DataLoaded.Invoke(sender, null);
}
}
}
public void SaveClicked(Stream data)
{
MemoryStream ms = new MemoryStream();
data.CopyTo(ms);
DashboardDTO dto = DashboardLayouts.Where(c => c.LayoutName == SelectedLayout).FirstOrDefault();
dto.DashboardLayout = ms.ToArray();
Context.SubmitChanges(Submit_Completed, null);
}
private void Submit_Completed(SubmitOperation operation)
{
if (operation.HasError)
{
MessageBox.Show(operation.Error.Message);
}
else
{
MessageBox.Show("Data saved successfully");
}
}
public Stream LoadClicked()
{
DashboardDTO dto = DashboardLayouts.Where(c => c.LayoutName == SelectedLayout).FirstOrDefault();
Stream str = new MemoryStream(dto.DashboardLayout);
return str;
}
private void StudentClicked()
{
StudentViewModel vm = Container.Resolve<StudentViewModel>();
object pview = RegionManager.Regions["MainRegion"].Views.FirstOrDefault(region => region.GetType().Equals(typeof(DashboardView)));
vm.ReturnView = pview;
if (pview != null)
{
RegionManager.Regions["MainRegion"].Remove(pview);
}
StudentView view = Container.Resolve<StudentView>();
vm.MyView = view;
view.DataContext = vm;
RegionManager.AddToRegion("MainRegion", view);
RegionManager.Regions["MainRegion"].Activate(view);
}
#region DragDrop functionality
public void OnDragQuery(object sender, DragDropQueryEventArgs e)
{
if (e.Options.Status == DragStatus.DragQuery && SelectedWidget != null)
{
e.Options.Payload = SelectedWidget;
ContentControl cue = new ContentControl();
cue.Content = SelectedWidget;
e.Options.DragCue = cue;
e.Options.ArrowCue = RadDragAndDropManager.GenerateVisualCue();
}
e.QueryResult = true;
}
public void OnDropQuery(object sender, DragDropQueryEventArgs e)
{
e.QueryResult = true;
}
public void OnDropInfo(object sender, DragDropEventArgs e)
{
if (e.Options.Status == DragStatus.DropComplete)
{
WidgetDTO widget = e.Options.Payload as WidgetDTO;
TileViewModel model = (e.OriginalSource as FrameworkElement).DataContext as TileViewModel;
Assembly assembly = Assembly.GetExecutingAssembly();
Type wType = assembly.GetType("SimpleModule.MyWidgets." + widget.Name);
RegionManager.RegisterViewWithRegion(model.Name, wType);
string w1 = widget.Name + ".xaml";
RegionManager.AddToRegion(model.Name, w1);
RegionManager.Regions[model.Name].Activate(w1);
}
}
#endregion
#endregion
}
}
and I have a directory of of Widgets in the SimpleModule.MyWidgets that are simply the user control with a hardcoded label.
...
I want to make it persistence by saving the stream in the database and then getting it back from there and applying it to the GUI.
I am stick here and didn't know what's i am doing wrong here..