Show unknown messages in the panel

This commit is contained in:
Morten Nielsen 2017-03-14 22:55:00 -07:00
parent add8429da9
commit d0bff9f06e
5 changed files with 103 additions and 15 deletions

View file

@ -3,25 +3,25 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:SampleApp.WinDesktop"
Title="Sample App" Height="500" Width="625">
<Grid>
<Grid.Resources>
<local:NullToCollapsedConverter x:Key="nullConv" />
<Style TargetType="UserControl" x:Key="card">
<Setter Property="Margin" Value="10" />
<Setter Property="Padding" Value="10" />
<Setter Property="Background" Value="White" />
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Direction="0" ShadowDepth="0"
<Window.Resources>
<local:NullToCollapsedConverter x:Key="nullConv" />
<Style TargetType="UserControl" x:Key="card">
<Setter Property="Margin" Value="10" />
<Setter Property="Padding" Value="10" />
<Setter Property="Background" Value="White" />
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect Direction="0" ShadowDepth="0"
BlurRadius="20" Opacity=".5" />
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<TabControl>
<TabItem Header="GPS Info">
<ScrollViewer HorizontalScrollBarVisibility="Disabled" Background="#FFEEEEEE">
<WrapPanel>
<WrapPanel x:Name="MessagePanel">
<local:GprmcControl x:Name="gprmcView" Style="{StaticResource card}" Visibility="{Binding Message, ElementName=gprmcView, Converter={StaticResource nullConv}}" />
<local:GpggaControl x:Name="gpggaView" Style="{StaticResource card}" Visibility="{Binding Message, ElementName=gpggaView, Converter={StaticResource nullConv}}" />
<local:GpgsaControl x:Name="gpgsaView" Style="{StaticResource card}" Visibility="{Binding Message, ElementName=gpgsaView, Converter={StaticResource nullConv}}" />

View file

@ -106,6 +106,23 @@ namespace SampleApp.WinDesktop
gpgllView.Message = args.Message as NmeaParser.Nmea.Gps.Gpgll;
else if (args.Message is NmeaParser.Nmea.Gps.Garmin.Pgrme)
pgrmeView.Message = args.Message as NmeaParser.Nmea.Gps.Garmin.Pgrme;
else if (args.Message is NmeaParser.Nmea.UnknownMessage)
{
var ctrl = MessagePanel.Children.OfType<UnknownMessageControl>().Where(c => c.Message.MessageType == args.Message.MessageType).FirstOrDefault();
if(ctrl == null)
{
ctrl = new UnknownMessageControl()
{
Style = this.Resources["card"] as Style
};
MessagePanel.Children.Add(ctrl);
}
ctrl.Message = args.Message as NmeaParser.Nmea.UnknownMessage;
}
else
{
//
}
});
}

View file

@ -66,6 +66,9 @@
<DependentUpon>KeyValuePairControl.xaml</DependentUpon>
</Compile>
<Compile Include="NullToCollapsedConverter.cs" />
<Compile Include="UnknownMessageControl.xaml.cs">
<DependentUpon>UnknownMessageControl.xaml</DependentUpon>
</Compile>
<Compile Include="PgrmeControl.xaml.cs">
<DependentUpon>PgrmeControl.xaml</DependentUpon>
</Compile>
@ -94,6 +97,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UnknownMessageControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="PgrmeControl.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>

View file

@ -0,0 +1,24 @@
<UserControl x:Class="SampleApp.WinDesktop.UnknownMessageControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SampleApp.WinDesktop"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<StackPanel DataContext="{Binding RelativeSource={RelativeSource AncestorType=UserControl}, Path=Message}">
<Border Background="LightGray" Padding="10" Margin="-10,-10,-10,5">
<TextBlock Text="{Binding MessageType}" x:Name="typeName" FontSize="20" FontWeight="Bold" Foreground="White" />
</Border>
<ItemsControl x:Name="Values" ItemsSource="{Binding Values}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="●" Margin="0,0,5,0" />
<TextBlock Text="{Binding}" />
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</UserControl>

View file

@ -0,0 +1,40 @@
using NmeaParser.Nmea;
using NmeaParser.Nmea.Gps;
using NmeaParser.Nmea.Gps.Garmin;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SampleApp.WinDesktop
{
/// <summary>
/// Interaction logic for UnknownMessageControl.xaml
/// </summary>
public partial class UnknownMessageControl : UserControl
{
public UnknownMessageControl()
{
InitializeComponent();
}
public UnknownMessage Message
{
get { return (UnknownMessage)GetValue(MessageProperty); }
set { SetValue(MessageProperty, value); }
}
public static readonly DependencyProperty MessageProperty =
DependencyProperty.Register("Message", typeof(NmeaParser.Nmea.UnknownMessage), typeof(UnknownMessageControl), new PropertyMetadata(null));
}
}