Upgrading from WPF Application Framework (WAF) 1.0
This topic describes how to upgrade a solution from version 1.0 to version 2.0 of the WPF Application Framework (WAF). It explains the breaking changes in the API and it shows how to solve them.
1. The .NET Framework 3.5 SP1 is not supported anymore
The .NET Framework 3.5 SP1 is not supported anymore. In order to upgrade to the WAF 2.0 libraries you need to upgrade your solution to a .NET Framework 4 solution as well.
2. The static class ViewExtension was renamed to ViewHelper
If you have used the static class
ViewExtension in your solution then you need to rename it to
ViewHelper. This can be done via the search and replace tool of Visual Studio.
3. The base class Model is marked as abstract
This breaking change affects you only if you have instantiated the
Model class directly.
The
Model class is now marked as "
abstract". This way you cannot instantiate this class directly anymore. However, you can inherit from
Model and instantiate your class.
4. The interface IMessageService has been modified
This breaking change affects you only if you have "implemented" this interface.
4.1 Owner Parameter
All methods defined in the
IMessageService interface have been extended by the new
owner parameter.
void ShowMessage(object owner, string message);
void ShowWarning(object owner, string message);
void ShowError(object owner, string message);
If you want to use the owner object in the interface implementation then you might need to cast the value to the
Window type:
Window ownerWindow = owner as Window;Remark: The owner parameter can be null.
4.2 ShowQuestion
Classes which implement the
IMessageService interface need to provide an implementation for the new methods
ShowQuestion and
ShowYesNoQuestion.
An example implementation of these methods is shown below:
public bool? ShowQuestion(object owner, string message)
{
Window ownerWindow = owner as Window;
MessageBoxResult result;
if (ownerWindow != null)
{
result = MessageBox.Show(ownerWindow, message, ApplicationInfo.ProductName, MessageBoxButton.YesNoCancel,
MessageBoxImage.Question, MessageBoxResult.Cancel, MessageBoxOptions);
}
else
{
result = MessageBox.Show(message, ApplicationInfo.ProductName, MessageBoxButton.YesNoCancel,
MessageBoxImage.Question, MessageBoxResult.Cancel, MessageBoxOptions);
}
if (result == MessageBoxResult.Yes) { return true; }
else if (result == MessageBoxResult.No) { return false; }
return null;
}
public bool ShowYesNoQuestion(object owner, string message)
{
Window ownerWindow = owner as Window;
MessageBoxResult result;
if (ownerWindow != null)
{
result = MessageBox.Show(ownerWindow, message, ApplicationInfo.ProductName, MessageBoxButton.YesNo,
MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions);
}
else
{
result = MessageBox.Show(message, ApplicationInfo.ProductName, MessageBoxButton.YesNo,
MessageBoxImage.Question, MessageBoxResult.No, MessageBoxOptions);
}
return result == MessageBoxResult.Yes;
}
5. The interface IFileDialogService has been modified
This breaking change affects you only if you have "implemented" this interface.
All methods defined in the
IFileDialogService interface have been extended by the new
owner parameter.
FileDialogResult ShowOpenFileDialog(object owner, IEnumerable<FileType> fileTypes,
FileType defaultFileType, string defaultFileName);
FileDialogResult ShowSaveFileDialog(object owner, IEnumerable<FileType> fileTypes,
FileType defaultFileType, string defaultFileName);
If you want to use the owner object in the interface implementation then you might need to cast the value to the
Window type:
Window ownerWindow = owner as Window;Remark: The owner parameter can be null.
6. The class MessageService has been modified.
All methods defined in the
MessageService class have been extended by the new object
owner parameter.
public void ShowMessage(object owner, string message) { ... }
public void ShowWarning(object owner, string message) { ... }
public void ShowError(object owner, string message) { ... }
Callers of these methods can pass
null for the owner parameter or the owning
Window of the
MessageBox.
7. The class FileDialogService has been modified.
All methods defined in the
FileDialogService class have been extended by the new object
owner parameter.
public FileDialogResult ShowOpenFileDialog(object owner, IEnumerable<FileType> fileTypes,
FileType defaultFileType, string defaultFileName) { ... }
public FileDialogResult ShowSaveFileDialog(object owner, IEnumerable<FileType> fileTypes,
FileType defaultFileType, string defaultFileName) { ... }
Callers of these methods can pass
null for the owner parameter or the owning
Window of the
FileDialog.