Add a Service View
The service view is used to control a module via the HMI, which is particularly useful for commissioning and troubleshooting.
Example
This example adds a service view to the module example .
Implement the IHasServiceView interface:
public class MyDeviceModule : LisrtModule, IInitializable, IHasServiceView
{
private MyDeviceServiceServiceViewModel _serviceViewModel;
public void ShowServiceView()
{
if (_serviceViewModel == null)
_serviceViewModel = new MyDeviceServiceServiceViewModel(this);
var shell = IoC.Get<IShell>();
shell.OpenDocument(_serviceViewModel);
}
}
Tip
Use the ServiceViewModelBase as base class.
By default, its IsEnabled depends on:
Module is Enabled = true
User has UseServiceWindow permission
If Module implements IInitializable, it must be initialized
If ManualOperatingMode exists, it must be the current mode.
internal class MyDeviceServiceViewModel : ServiceViewModelBase
{
private readonly new MyDeviceModule _module;
public MyDeviceServiceViewModel(MyDeviceModule module)
: base(module)
{
_module = module;
_module.PropertyChanged += ModulePropertyChanged;
DoCommand = new AsyncExceptionHandlingRelayCommand(
execute: (_) => _module.Do(),
canExecute: (_) => _module.InitializationState == Contracts.InitializationState.Initialized);
}
public int MyConfiguration => _module.MyConfiguration;
public string MyState => _module.MyState;
public ICommand DoCommand { get; }
// IMPORTANT Notify changes of properties of your module!
private void ModulePropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(MyDeviceModule.MyConfiguration))
NotifyOfPropertyChange(nameof(MyConfiguration));
if (e.PropertyName == nameof(MyDeviceModule.MyState))
NotifyOfPropertyChange(nameof(MyState));
}
}
Tip
Add a to the service view, so that the user can scroll if it doesn't fit on the screen.
<UserControl x:Class="Loehnert.Lisrt.Modules.Docs.Demo.Modules.Views.MyDeviceServiceView"
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:loe="clr-namespace:Loehnert.Controls;assembly=Loehnert.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:viewmodels="clr-namespace:Loehnert.Lisrt.Modules.Docs.Demo.Modules.ViewModels"
d:DataContext="{d:DesignInstance Type=viewmodels:MyDeviceServiceViewModel}"
d:DesignHeight="450"
d:DesignWidth="800"
mc:Ignorable="d">
<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
<!-- IMPORTANT: Bind the IsEnabled property. -->
<Grid IsEnabled="{Binding IsEnabled}">
<loe:ContentContainer Description="{Binding Title}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- MyConfiguration property -->
<Label Grid.Row="0"
Grid.Column="0"
Content="My Configuration" />
<Label Grid.Row="0"
Grid.Column="1"
Content="{Binding MyConfiguration}" />
<!-- MyState property -->
<Label Grid.Row="1"
Grid.Column="0"
Content="My State" />
<Label Grid.Row="1"
Grid.Column="1"
Content="{Binding MyState}" />
<!-- Do method -->
<Button Grid.Row="2"
Grid.Column="0"
Command="{Binding DoCommand}"
Content="Do" />
</Grid>
</loe:ContentContainer>
</Grid>
</ScrollViewer>
</UserControl>
See Also