bovender framework
C# framework that implements MVVM and more
ShowViewAction.cs
1
/* ShowViewAction.cs
2
* part of Daniel's XL Toolbox NG
3
*
4
* Copyright 2014-2018 Daniel Kraus
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*/
18
using
System
;
19
using
System
.Collections.Generic;
20
using
System
.Linq;
21
using
System
.Text;
22
using
System
.Windows;
23
using
Bovender
.
Mvvm
.
Messaging
;
24
using
Bovender
.
Extensions
;
25
26
namespace
Bovender
.Mvvm.Actions
27
{
32
public
class
ShowViewAction
:
NotificationAction
33
{
34
#region Public properties
35
36
public
string
Assembly {
get
;
set
; }
37
public
string
View {
get
;
set
; }
38
39
#endregion
40
41
#region Overrides
42
43
protected
override
Window
CreateView
()
44
{
45
object
obj = Activator.CreateInstance(Assembly, View).Unwrap();
46
Window view = obj as Window;
47
if
(view != null)
48
{
49
Logger.Info(
"CreateView: Created {0}"
, view.GetType().FullName);
50
return
view;
51
}
52
else
53
{
54
Logger.Fatal(
"Class {0} in assembly {1} is not derived from Window"
, Assembly, View);
55
throw
new
ArgumentException(String.Format(
56
"Class '{0}' in assembly '{1}' is not derived from Window."
,
57
Assembly, View));
58
}
59
}
60
61
protected
override
void
ShowView
(Window view)
62
{
63
view.ShowInForm();
64
}
65
66
protected
override
ViewModels.ViewModelBase
GetDataContext
(
MessageContent
messageContent)
67
{
68
ViewModelMessageContent
vmc = messageContent as
ViewModelMessageContent
;
69
if
(vmc != null)
70
{
71
return
vmc.
ViewModel
;
72
}
73
else
74
{
75
Logger.Fatal(
"GetDataContext: Expected ViewModelMessageContent, got {0}"
,
76
messageContent == null ?
"null"
: messageContent.GetType().FullName);
77
throw
new
ArgumentException(
"Invalid message content: ShowViewAction requires ViewModelMessageContent"
);
78
}
79
}
80
81
#endregion
82
83
#region Class logger
84
85
private
static
NLog
.Logger Logger {
get
{
return
_logger.Value; } }
86
87
private
static
readonly Lazy<
NLog
.Logger> _logger =
new
Lazy<
NLog
.Logger>(() =>
NLog
.LogManager.GetCurrentClassLogger());
88
89
#endregion
90
}
91
}
Bovender.Mvvm.Actions.ShowViewAction
Injects a view with a view model that is referenced in a ViewModelMessageContent, and shows the view ...
Definition:
ShowViewAction.cs:32
Bovender.Mvvm.Messaging.ViewModelMessageContent
Message content that holds a reference to a view model.
Definition:
ViewModelMessageContent.cs:29
Bovender.Mvvm.Messaging.ViewModelMessageContent.ViewModel
ViewModelBase ViewModel
Definition:
ViewModelMessageContent.cs:39
Bovender.Mvvm.Messaging
Definition:
DownloadProcessMessageContent.cs:24
Bovender.Extensions
Definition:
ArrayExtensions.cs:23
Bovender.Mvvm.Actions.ShowViewAction.GetDataContext
override ViewModels.ViewModelBase GetDataContext(MessageContent messageContent)
Gets a ViewModelBase object that will be injected into the view In the abstract base class...
Definition:
ShowViewAction.cs:66
Bovender.Mvvm
Bovender
Definition:
ComHelpers.cs:24
System
Bovender.Mvvm.Actions.ShowViewAction.ShowView
override void ShowView(Window view)
Shows the view as a modal dialog.
Definition:
ShowViewAction.cs:61
Bovender.Mvvm.Actions.ShowViewAction.CreateView
override Window CreateView()
Returns a view that can bind to expected message contents.
Definition:
ShowViewAction.cs:43
NLog
Bovender.Mvvm.Messaging.MessageContent
Simple object that encapsulates a boolean value; to be used in MVVM interaction with MessageArgs...
Definition:
MessageContent.cs:26
Bovender.Mvvm.Actions.NotificationAction
Opens a generic WPF dialog window that displays a message and has a single OK button.
Definition:
NotificationAction.cs:33
Bovender
Mvvm
Actions
ShowViewAction.cs
Generated on Tue Aug 14 2018 13:04:33 for bovender framework by
1.8.11