tags:

views:

38

answers:

1

I'm hoping for some insight from someone better experienced than I for creating a window/set of windows for displaying data in WPF. Here is a little overview of my task:

  • I will getting a large amount of binary output from a receiver. This will then be parsed and keyed to the meaning of the particular bit (i.e. word1 bit1 = Receiver Status OK") for each binary string.

  • The data must then be displayed in a simple window of some sort in the format Receiver Status OK [CheckBox bound to value], or Speed in X direction: [TextBlock bound to value]

The issues are as follows:

  • There are around 60 unique 'messages' that need to be displayed when the user needs to look at the incoming data

  • Each message is of a different length of words, each with different meanings and a different number of fields that will have to be displayed.

I would like to know how you would approach this situation. I was thinking of going brute force, one window per message, but that seems very raw. My other thought was making a single standard window with a grid that was the size of the largest message, and then populating it with necessary TextBlocks and such. Then, I just DataBind the keys and values to the fields for each message, and Collapse the unused fields.

Any suggestions would be greatly appreciated. Thank you in advance.

A: 

It sounds like you have a bunch of concrete message classes. If this is the case, I would create a new DataTemplate for each of the messages in the Window's Resources. The DataTemplate's x:Key should be set to the type of the class it is representing. Then, you would set the Content of the Window to the instance of the message, and it will select the correct DataTemplate for the type.

e.g.

<Window x:Class="MessageTest.MessageWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:lcl="clr-namespace:MessageTest">

    <Window.Resources>
        <DataTemplate x:Key="{x:Type lcl:SimpleMessage}">
            <TextBlock Text="{Binding MessageContent}" />
        </DataTemplate>
    </Window.Resources>

</Window>

And when you create the Window:

private void MessageRecieved(IMessage message)
{
    var window = new MessageWindow { Content = message };
    window.Show();
}
Abe Heidebrecht
This sounds like a fantastic plan! I'll give this a shot. Thank you!
CaffeineZombie