<!--
    Software-Disclaimer Deutsch

    Bezeichnung/Dateiname (mit Version): Demo1 (1.4.0)
    Funktion: Die hiervorliegende Software soll in einfacher Form die Funktionsweise und Umgang mit einem OPC-Server inkl. Turck RFID HF/UHF erklären.

    Die hier vorliegende Software wird unentgeltlich und nur in dem verfügbaren Zustand bereitgestellt.
    Jedwede Haftung ist auf Fälle von Vorsatz und grober Fahrlässigkeit beschränkt. TURCK übernimmt keinerlei Gewährleistung, insbesondere nicht für Eignung und Funktionsfähigkeit. Die Software darf nur für die jeweils vorgesehene Hardware verwendet werden. Sie ist ausschließlich von Fachpersonal mit entsprechender Ausbildung einzusetzen.
    Die Anwender sind für den sachgemäßen Betrieb sowie für die Einhaltung aller geltenden Normen und Vorschriften selbst verantwortlich.
    Ergänzend gelten die Bedingungen der Softwareklausel zur Überlassung von Standard-Software als Teil von Lieferungen des ZVEI e.V. sowie die Allgemeine Lieferbedingungen für Erzeugnisse und Leistungen der Elektroindustrie des ZVEI e.V. (verfügbar unter www.turck.com/agb).

    Software-Disclaimer English

    Description/filename (with version): Demo1 (1.4.0)
    Function: This software should explain in a simple way how an OPC server including Turck RFID HF/UHF works and how to use it.

    The software available here is provided free of charge and only "as is".
    Any liability is limited to cases of intent and gross negligence. TURCK does not assume any warranty, especially not for suitability and functionality. The software may only be used for the provided hardware. It is to be used exclusively by qualified personnel with appropriate professional training.
    Each user is responsible for proper handling and compliance with all applicable standards and regulations.
    In addition, the Software Clause for the Provision of Standard Software as Part of Supplies of the ZVEI e.V. and the General Conditions for the Supply of Products and Services of the Electrical and Electronics Industry of the ZVEI (available at www.turck.com/agb) shall apply.
-->
<Window
    x:Class="Demo1.View.MainView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:command="http://www.galasoft.ch/mvvmlight"
    xmlns:converter="clr-namespace:DemoLib.Converter;assembly=DemoLib"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
    xmlns:loading="clr-namespace:LoadingIndicators.WPF;assembly=LoadingIndicators.WPF"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:viewModel="clr-namespace:Demo1.ViewModel"
    Title="OPC UA Client Demo V1.4.0 - Complete RFID functionality"
    Width="800"
    Height="600"
    MinWidth="800"
    MinHeight="600"
    Icon="/DemoLib;Component/Ressource/Logo.ico"
    mc:Ignorable="d">
    <Window.DataContext>
        <viewModel:MainViewModel />
    </Window.DataContext>
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingWave.xaml" />
                <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingThreeDots.xaml" />
                <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingFlipPlane.xaml" />
                <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingPulse.xaml" />
                <ResourceDictionary Source="pack://application:,,,/LoadingIndicators.WPF;component/Styles/LoadingDoubleBounce.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <converter:ByteLengthInHexLengthConverter x:Key="ByteLengthInHexLengthConverter" />
            <converter:InvertBoolConverter x:Key="InvertBoolConverter" />
            <converter:BooleanAndConverter x:Key="MultiBooleanAndConverter" />
            <converter:BooleanToVisibilityConverter
                x:Key="VisibilityConverter"
                FalseState="Collapsed"
                TrueState="Visible" />
            <converter:ListViewCountNumberConverter x:Key="ListViewCountNumberConverter" />
        </ResourceDictionary>
    </Window.Resources>
    <i:Interaction.Triggers>
        <i:EventTrigger EventName="Closing">
            <command:EventToCommand Command="{Binding WindowCloseingCommand}" PassEventArgsToCommand="True" />
        </i:EventTrigger>
    </i:Interaction.Triggers>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" MinHeight="100" />
            <RowDefinition Height="5" />
            <RowDefinition Height="*" MinHeight="100" />
            <RowDefinition Height="5" />
            <RowDefinition Height="*" MinHeight="100" />
        </Grid.RowDefinitions>
        <Grid Grid.Row="0" Background="#FFFFCC00">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <Image
                Grid.Column="1"
                Height="40"
                Source="/DemoLib;Component/Ressource/Turck-Stand alone_2015_RGB.jpg" />
        </Grid>
        <Grid Margin="5" Row="1">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal">
                <TextBlock
                    Width="50"
                    VerticalAlignment="Center"
                    Text="Server: "
                    TextAlignment="Right" />
                <TextBox
                    Width="150"
                    IsEnabled="{Binding Connected, Converter={StaticResource InvertBoolConverter}}"
                    Text="{Binding Server, UpdateSourceTrigger=PropertyChanged}" />
                <TextBlock
                    Width="50"
                    VerticalAlignment="Center"
                    Text="Port: "
                    TextAlignment="Right" />
                <TextBox
                    Width="80"
                    IsEnabled="{Binding Connected, Converter={StaticResource InvertBoolConverter}}"
                    PreviewTextInput="Number_PreviewTextInput"
                    Text="{Binding Port, UpdateSourceTrigger=PropertyChanged}" />
                <Button
                    Width="80"
                    Margin="5,0"
                    Command="{Binding ConnectCommand}"
                    Content="Connect" />
                <Button
                    Width="80"
                    Command="{Binding DisconnectCommand}"
                    Content="Disconnect" />
            </StackPanel>
            <TextBlock
                Grid.Column="1"
                VerticalAlignment="Center"
                Text="{Binding WatchResultTime.TotalMilliseconds, StringFormat={}{0} ms}" />
        </Grid>
        <StackPanel
            Grid.Row="2"
            Margin="5"
            Orientation="Horizontal">
            <TextBlock
                Width="50"
                VerticalAlignment="Center"
                Text="Reader: "
                TextAlignment="Right" />
            <ComboBox
                Width="195"
                ItemsSource="{Binding ReaderList}"
                SelectedItem="{Binding SelectedReader}">
                <ComboBox.IsEnabled>
                    <MultiBinding Converter="{StaticResource MultiBooleanAndConverter}">
                        <Binding Path="Connected" />
                        <Binding Converter="{StaticResource InvertBoolConverter}" Path="RunningScan" />
                    </MultiBinding>
                </ComboBox.IsEnabled>
                <ComboBox.ItemTemplate>
                    <DataTemplate>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="{Binding Ident}" />
                            <TextBlock
                                Margin="5,0"
                                Foreground="Gray"
                                Text="{Binding Type}" />
                            <TextBlock Foreground="Gray" Text="{Binding Name, StringFormat={} Name: {0}}" />
                        </StackPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
            </ComboBox>
            <Button
                Width="80"
                Margin="5,0"
                Command="{Binding ShowReaderInfoCommand}"
                Content="Info" />
            <Button
                Width="80"
                Margin="0,0,5,0"
                Command="{Binding ShowBusModeCommand}"
                Content="BusMode" />
            <Button
                Width="80"
                Command="{Binding EditReaderNameCommand}"
                Content="Edit name" />
            <Button
                Width="80"
                Margin="5,0"
                Command="{Binding RefreshReaderListCommand}"
                Content="Refresh" />
            <TextBlock
                Margin="5,0"
                VerticalAlignment="Center"
                Text="{Binding ReaderStatus, StringFormat={}Status: {0}}" />
        </StackPanel>
        <Grid Margin="5" Row="3">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <StackPanel
                    Grid.Row="0"
                    VerticalAlignment="Center"
                    Orientation="Horizontal">
                    <Button
                        x:Name="ScanButton"
                        Width="80"
                        Command="{Binding ScanCommand}"
                        CommandParameter="{Binding Path=IsChecked, ElementName=DataAviarible}"
                        Content="Scan" />
                    <StackPanel Margin="5,0,0,0">
                        <StackPanel Margin="0,0,0,4" Orientation="Horizontal">
                            <RadioButton
                                VerticalAlignment="Center"
                                GroupName="scanMethod"
                                IsChecked="True"
                                IsEnabled="{Binding ElementName=ScanButton, Path=IsEnabled}" />
                            <TextBlock
                                Margin="5,0,0,0"
                                VerticalAlignment="Center"
                                Text="Cycles: "
                                TextAlignment="Right" />
                            <TextBox
                                Width="25"
                                IsEnabled="{Binding IsEnabled, ElementName=ScanButton}"
                                MaxLength="2"
                                PreviewTextInput="Number_PreviewTextInput"
                                Text="{Binding Cycles}" />
                            <TextBlock
                                Width="60"
                                VerticalAlignment="Center"
                                Text="Duration: "
                                TextAlignment="Right" />
                            <TextBox
                                Width="50"
                                IsEnabled="{Binding IsEnabled, ElementName=ScanButton}"
                                MaxLength="5"
                                PreviewTextInput="Number_PreviewTextInput"
                                Text="{Binding Duration}" />
                            <TextBlock
                                Margin="2,0"
                                VerticalAlignment="Center"
                                Text="ms" />
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <RadioButton
                                x:Name="DataAviarible"
                                GroupName="scanMethod"
                                IsEnabled="{Binding ElementName=ScanButton, Path=IsEnabled}" />
                            <TextBlock Margin="5,0" Text="Data available" />
                        </StackPanel>
                    </StackPanel>

                    <Rectangle
                        Width="1"
                        Margin="3,2"
                        VerticalAlignment="Stretch"
                        Stroke="#FFA0A0A0" />
                    <Button
                        Width="80"
                        Command="{Binding ScanStartCommand}"
                        Content="Scan start" />
                    <Button
                        Width="80"
                        Margin="5,0"
                        Command="{Binding ScanStopCommand}"
                        Content="Scan stop" />
                    <TextBlock VerticalAlignment="Center" Text="{Binding ScanStatus, StringFormat={}Scan status: {0}}" />
                </StackPanel>
                <StackPanel
                    Grid.Row="0"
                    HorizontalAlignment="Right"
                    Orientation="Horizontal">
                    <Button
                        Width="80"
                        Command="{Binding ClearTagsCommand}"
                        Content="Clear Tags" />
                </StackPanel>
                <TextBlock
                    Grid.Row="1"
                    Margin="5,0"
                    VerticalAlignment="Center"
                    Text="Found Tags:" />

                <ListBox
                    Grid.Row="2"
                    ItemsSource="{Binding Tags}"
                    ScrollViewer.CanContentScroll="False"
                    SelectedItem="{Binding SelectedTag}">
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel>
                                <StackPanel Orientation="Horizontal">
                                    <TextBlock Text="{Binding Timestamp}" />
                                    <TextBlock Margin="5,0" Text="{Binding IdentiferString, StringFormat={}Tag: {0}}" />
                                </StackPanel>
                                <Expander Header="Strengths">
                                    <ItemsControl ItemsSource="{Binding Sightings}">
                                        <ItemsControl.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding TimestampTime, StringFormat={}Timestamp: {0}}" />
                                                    <TextBlock Margin="5,0" Text="{Binding Strength, StringFormat={}Strength: {0}}" />
                                                    <TextBlock Text="{Binding Antenna, StringFormat={}Antenna: {0}}" />
                                                    <TextBlock Margin="5,0" Text="{Binding CurrentPowerLevel, StringFormat={}PowerLevel: {0}}" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </ItemsControl.ItemTemplate>
                                    </ItemsControl>
                                </Expander>
                            </StackPanel>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
                <loading:LoadingIndicator
                    Grid.Row="2"
                    IsActive="{Binding RunningScan}"
                    SnapsToDevicePixels="True"
                    Style="{DynamicResource LoadingIndicatorWaveStyleKey}" />
            </Grid>
        </Grid>
        <GridSplitter
            Grid.Row="4"
            Width="100"
            Margin="0,1"
            HorizontalAlignment="Center"
            Background="White"
            BorderBrush="#FFFFCC00"
            BorderThickness="1"
            ResizeBehavior="PreviousAndNext"
            ResizeDirection="Rows" />
        <Grid Margin="5" Row="5">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>
                <Grid Row="0">
                    <StackPanel Orientation="Horizontal">
                        <Button
                            x:Name="ReadTagButton"
                            Width="80"
                            Command="{Binding ReadTagCommand}"
                            Content="Read Tag" />
                        <Rectangle
                            Width="1"
                            Margin="3,2"
                            VerticalAlignment="Stretch"
                            Stroke="#FFA0A0A0" />
                        <Button
                            x:Name="WriteTagButton"
                            Width="80"
                            Command="{Binding WriteTagCommand}"
                            Content="Write Tag" />
                        <StackPanel Margin="5,0">
                            <StackPanel Margin="0,0,0,2" Orientation="Horizontal">
                                <TextBlock
                                    VerticalAlignment="Center"
                                    Text="Offset: "
                                    TextAlignment="Right" />
                                <TextBox
                                    Width="40"
                                    IsEnabled="{Binding IsEnabled, ElementName=ReadTagButton}"
                                    PreviewTextInput="Number_PreviewTextInput"
                                    Text="{Binding TagDataOffset}"
                                    ToolTip="in byte" />
                                <TextBlock
                                    Width="50"
                                    VerticalAlignment="Center"
                                    Text=" Bytes" />
                                <TextBlock
                                    VerticalAlignment="Center"
                                    Text="Length: "
                                    TextAlignment="Right" />
                                <TextBox
                                    x:Name="LengthText"
                                    Width="40"
                                    IsEnabled="{Binding IsEnabled, ElementName=ReadTagButton}"
                                    PreviewTextInput="Number_PreviewTextInput"
                                    Text="{Binding TagDataLength}"
                                    ToolTip="in byte" />
                                <TextBlock
                                    Width="50"
                                    VerticalAlignment="Center"
                                    Text=" Bytes" />
                                <Button
                                    Width="80"
                                    Margin="5,0"
                                    Command="{Binding RandomBytesCommand}"
                                    Content="Random Data" />
                            </StackPanel>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock
                                    Width="90"
                                    VerticalAlignment="Center"
                                    Text="Write User Data: "
                                    TextAlignment="Right"
                                    ToolTip="in HEX Values" />
                                <TextBox
                                    Width="400"
                                    IsEnabled="{Binding IsEnabled, ElementName=ReadTagButton}"
                                    MaxLength="{Binding Text, ElementName=LengthText, Converter={StaticResource ByteLengthInHexLengthConverter}}"
                                    PreviewTextInput="TextBox_PreviewTextInput"
                                    Text="{Binding WriteDataTag, UpdateSourceTrigger=PropertyChanged}" />
                            </StackPanel>
                        </StackPanel>
                    </StackPanel>
                    <StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
                        <Button
                            Width="80"
                            Command="{Binding ClearOutputsCommand}"
                            Content="Clear Outputs" />
                    </StackPanel>
                </Grid>
                <TextBlock
                    Grid.Row="1"
                    Margin="5,0"
                    VerticalAlignment="Center"
                    Text="Outputs:" />
                <ListBox Grid.Row="3" ItemsSource="{Binding Outputs}" />
            </Grid>
        </Grid>
        <GridSplitter
            Grid.Row="6"
            Width="100"
            Margin="0,1"
            HorizontalAlignment="Center"
            Background="White"
            BorderBrush="#FFFFCC00"
            BorderThickness="1"
            ResizeBehavior="PreviousAndNext"
            ResizeDirection="Rows" />
        <Grid Grid.Row="7" Margin="5">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <TextBlock
                Grid.Row="0"
                Margin="5,0"
                VerticalAlignment="Bottom"
                Text="Events (Please select an item to show RFID tag in found tags):" />
            <StackPanel
                Grid.Row="0"
                HorizontalAlignment="Right"
                Orientation="Horizontal">
                <Button
                    Width="80"
                    Margin="0,0,0,5"
                    Command="{Binding ClearEventsCommand}"
                    Content="Clear Events" />
            </StackPanel>
            <ListView
                Grid.Row="1"
                IsEnabled="{Binding Connected}"
                ItemsSource="{Binding ReaderEvents}"
                SelectedItem="{Binding SelectedEvent}">
                <ListView.View>
                    <GridView>
                        <GridViewColumn Width="30" DisplayMemberBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListViewItem}}, Converter={StaticResource ListViewCountNumberConverter}}" />
                        <GridViewColumn
                            Width="60"
                            DisplayMemberBinding="{Binding Ident}"
                            Header="Ident" />
                        <GridViewColumn
                            Width="150"
                            DisplayMemberBinding="{Binding Time}"
                            Header="Time" />
                        <GridViewColumn
                            Width="60"
                            DisplayMemberBinding="{Binding Severity}"
                            Header="Severity" />
                        <GridViewColumn
                            Width="400"
                            DisplayMemberBinding="{Binding Message}"
                            Header="Message" />
                    </GridView>
                </ListView.View>
            </ListView>
        </Grid>
        <Grid
            Margin="5"
            Background="White"
            Opacity="0.8"
            Row="2"
            RowSpan="6"
            Visibility="{Binding RunningConnect, Converter={StaticResource VisibilityConverter}}">
            <loading:LoadingIndicator
                Width="100"
                Height="100"
                IsActive="true"
                SnapsToDevicePixels="True"
                Style="{DynamicResource LoadingIndicatorThreeDotsStyleKey}" />
        </Grid>
    </Grid>
</Window>