mercredi 24 avril 2019

Different properties interpreting of some constant object in WPF

I have a data packet, that body is consist of byte array. Also I need interprete a packet fields in few variations, but the body is still constant. For example: AA-BB-CC-DD-EE-FF - constant packet's body. In first interpretation: AA-BB-CC - as a Parameter 1 and DD-EE-FF - as a Parameter 2. In second variation: AA-BB - as a Parameter 3, CC-DD - Parameter 4, and EE-FF - Parameter 5. And so on.

I see few options to realize such behavior:

  1. In single class create all of the needed properties (parameter 1...parameter 5), and in caller class check the variation flag.
  2. Create few derived classes, and each class contains only specific properties (parameters 1 and 2 in first case, parameters from 3 to 5 - in the second).

Now to show packets in WPF I use 1st option. I have ListView and it's style as GridView:

<ListView x:Name="lv" />

When I need to visualize packets in first interpretation:

lv.Style = CType(TryFindResource("packetsStyle_1"), Style)

The packetsStyle_1 contains columns "Parameter 1" and "Parameter 2".

When I need to visualize packets in other interpretation, I just change the style of ListView:

lv.Style = CType(TryFindResource("packetsStyle_2"), Style)

The packetsStyle_2 contains columns "Parameter 3", "Parameter 4" and "Parameter 5".

This kind of realization is not object-oriented, as I understand. I want to do this with the OOP (option 2) - base class of packet with common properties and inherited classes with specific properties. But what is the WPF way to refresh GUI in this case? Do I need create two objects List(of PacketVar1) and List(of PacketVar2) and change ListView item's source and style? But list of packets is huge enough, and takes a lot of memory. Or what is the right implementation?

Aucun commentaire:

Enregistrer un commentaire