4 using System.Collections.Generic;
7 using System.Windows.Controls;
9 using System.Windows.Input;
10 using SiliconStudio.Quantum;
12 using System.Windows.Data;
14 namespace SiliconStudio.Presentation.Controls
25 this.Loaded += OnLoaded;
30 base.OnInitialized(e);
32 UpdateContentStateProperties(LoadState);
35 UpdateContentProperties();
41 RequestContentLoading();
46 public bool LoadContentOnInitialized
48 get {
return (
bool)GetValue(LoadContentOnInitializedProperty); }
49 set { SetValue(LoadContentOnInitializedProperty, value); }
52 public static readonly DependencyProperty LoadContentOnInitializedProperty = DependencyProperty.Register(
53 "LoadContentOnInitialized",
56 new PropertyMetadata(
false));
60 public bool IsContentNotLoaded
62 get {
return (
bool)GetValue(IsContentNotLoadedProperty); }
63 private set { SetValue(IsContentNotLoadedPropertyKey, value); }
66 private static readonly DependencyPropertyKey IsContentNotLoadedPropertyKey = DependencyProperty.RegisterReadOnly(
70 new PropertyMetadata());
71 public static readonly DependencyProperty IsContentNotLoadedProperty = IsContentNotLoadedPropertyKey.DependencyProperty;
75 public bool IsContentLoading
77 get {
return (
bool)GetValue(IsContentLoadingProperty); }
78 private set { SetValue(IsContentLoadingPropertyKey, value); }
81 private static readonly DependencyPropertyKey IsContentLoadingPropertyKey = DependencyProperty.RegisterReadOnly(
85 new PropertyMetadata());
86 public static readonly DependencyProperty IsContentLoadingProperty = IsContentLoadingPropertyKey.DependencyProperty;
90 public bool IsContentLoaded
92 get {
return (
bool)GetValue(IsContentLoadedProperty); }
93 private set { SetValue(IsContentLoadedPropertyKey, value); }
96 private static readonly DependencyPropertyKey IsContentLoadedPropertyKey = DependencyProperty.RegisterReadOnly(
100 new PropertyMetadata());
101 public static readonly DependencyProperty IsContentLoadedProperty = IsContentLoadedPropertyKey.DependencyProperty;
105 public object AwaitingContent
107 get {
return GetValue(AwaitingContentProperty); }
108 set { SetValue(AwaitingContentProperty, value); }
111 public static readonly DependencyProperty AwaitingContentProperty = DependencyProperty.Register(
118 public DataTemplate AwaitingContentTemplate
120 get {
return (DataTemplate)GetValue(AwaitingContentTemplateProperty); }
121 set { SetValue(AwaitingContentTemplateProperty, value); }
124 public static readonly DependencyProperty AwaitingContentTemplateProperty = DependencyProperty.Register(
125 "AwaitingContentTemplate",
126 typeof(DataTemplate),
134 set { SetValue(AwaitingContentTemplateSelectorProperty, value); }
137 public static readonly DependencyProperty AwaitingContentTemplateSelectorProperty = DependencyProperty.Register(
138 "AwaitingContentTemplateSelector",
147 set { SetValue(LoadStateProperty, value); }
150 public static readonly DependencyProperty LoadStateProperty = DependencyProperty.Register(
154 new FrameworkPropertyMetadata(
ViewModelContentState.NotLoaded, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnLoadStatePropertyChanged),
155 OnValidateLoadStateValue);
163 acc.UpdateContentStateProperties(newState);
164 acc.UpdateContentProperties();
166 acc.OnLoadStateChanged(oldState, newState);
171 IsContentNotLoaded = newState == ViewModelContentState.NotLoaded;
172 IsContentLoading = newState == ViewModelContentState.Loading;
173 IsContentLoaded = newState == ViewModelContentState.Loaded;
178 RaiseEvent(
new RoutedPropertyChangedEventArgs<ViewModelContentState>(oldValue, newValue, LoadStateChangedEvent));
186 public static readonly RoutedEvent LoadStateChangedEvent = EventManager.RegisterRoutedEvent(
188 RoutingStrategy.Bubble,
189 typeof(DependencyPropertyChangedEventHandler),
192 public event DependencyPropertyChangedEventHandler LoadStateChanged
194 add { AddHandler(LoadStateChangedEvent, value); }
195 remove { RemoveHandler(LoadStateChangedEvent, value); }
202 OnRequestContentLoading();
207 var command = LoadContentCommand;
208 if (command != null && command.CanExecute(null))
209 command.Execute(null);
214 public ICommand LoadContentCommand
216 get {
return (ICommand)GetValue(LoadContentCommandProperty); }
217 set { SetValue(LoadContentCommandProperty, value); }
220 public static readonly DependencyProperty LoadContentCommandProperty = DependencyProperty.Register(
221 "LoadContentCommand",
227 public ICommand CancelContentLoadingCommand
229 get {
return (ICommand)GetValue(CancelContentLoadingCommandProperty); }
230 set { SetValue(CancelContentLoadingCommandProperty, value); }
233 public static readonly DependencyProperty CancelContentLoadingCommandProperty = DependencyProperty.Register(
234 "CancelContentLoadingCommand",
240 private object storedContent;
241 private object storedContentTemplate;
242 private object storedContentTemplateSelector;
246 storedContent = GetPropertyValue(ContentProperty);
247 storedContentTemplate = GetPropertyValue(ContentTemplateProperty);
248 storedContentTemplateSelector = GetPropertyValue(ContentTemplateSelectorProperty);
251 private void UpdateContentProperties()
255 SetValue(ContentProperty, AwaitingContent);
256 SetValue(ContentTemplateProperty, AwaitingContentTemplate);
257 SetValue(ContentTemplateSelectorProperty, AwaitingContentTemplateSelector);
261 SetPropertyValue(ContentProperty, storedContent);
262 SetPropertyValue(ContentTemplateProperty, storedContentTemplate);
263 SetPropertyValue(ContentTemplateSelectorProperty, storedContentTemplateSelector);
267 private object GetPropertyValue(DependencyProperty property)
269 object result = null;
271 if (BindingOperations.IsDataBound(
this, property))
273 result = BindingOperations.GetBindingBase(
this, property);
275 result = BindingOperations.GetBindingExpressionBase(
this, property);
278 result = GetValue(property);
283 private void SetPropertyValue(DependencyProperty property,
object value)
285 if (value is BindingBase)
286 SetBinding(property, (BindingBase)value);
287 else if (value is BindingExpressionBase)
288 SetBinding(property, ((BindingExpressionBase)value).ParentBindingBase);
290 SetValue(property, value);
void RequestContentLoading()
override void OnInitialized(EventArgs e)
static bool OnValidateLoadStateValue(object value)
virtual void OnRequestContentLoading()
virtual void OnLoadStateChanged(ViewModelContentState oldValue, ViewModelContentState newValue)
static void OnLoadStatePropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)