Category Archives: MVVM

ASP.NET Adventure. My new project using SignalR.

image

I’m currently working on a set of applications to handle the main tasks of my family’s restaurant. This is a snapshot of the client for the kitchen. It’s on a very early state, but you can mark product orders as “Done”. It uses Entity Framework and some concepts of Domain-Driven Design. It’s also using Windows 8.1 and Windows Phone 8 for the clients (the waiters will have another kind of client to request orders to the kitchen.

SignalR is needed to notify waiters when an order is ready (or even when a product is ready). I wanted to share the progress on this! Smile For the moment, I think Windows 8 is a bit limiting in terms of layout. WPF is far more complete. But it doesn’t feel bad at all. I think the lack of Triggers for Styles will be a big headache, but some people are working on a MVVM-friendly way to face this using Visual States.

I also feel the asynchrony will be a major let down in a later stage of the solution, but with a bit of help, it can be done. I want to start it simple!

I hope you like it. The background is a bit lame, but I like blue hues! haha Open-mouthed smile

Hey, my picture appears in each order, but a picture of each waiter will appear in a few iterations, of course Smile with tongue out

Advertisements

ViewModels: make them right!

It’s not so simple to just make a class implement the INotifyPropertyChanged and create some properties.

Normally you have to REPRESENT a model. But how? Replicating the properties in the model that you want? Exposing the model itself using a property?

That is a good question that every MVVM lover should have asked himself when writhing a ViewModel.

You can take a look at this article. It really hits the nail on the head.

http://msdn.microsoft.com/en-us/magazine/ff798279.aspx

I normally expose the model directly and make UI classes that implement INotifyPropertyChanged. But I see the property mapping far more elegant and pure MVVMish 😉

What do you prefer?

¡Menús dinámicos! Harás cacota si no sabes esto

Imagina lo siguiente: Tienes un menú que se compone mediante un binding, pero resulta que es una combinación de varias colecciones. Por ejemplo, un menú que presenta una serie de opciones fijas (o variables), y entre medias, una colección enlazada con Binding. Pues colleiga, ¡se hace así!

<MenuItem.ItemsSource>

    <CompositeCollection>

        <!--<MenuItem Header="Menú de coña1" />

        <MenuItem Header="Menú de coña2" />

        <Separator/>-->

        <CollectionContainer Collection="{Binding Source={StaticResource EditorsCollectionViewSource}}" />

        <!--<Separator/>

        <MenuItem Header="Menú de coña3" />-->

    </CompositeCollection>

</MenuItem.ItemsSource>

Con la ayuda de un lobo de mar que dejó su info en Internet, ¡como los buenos samaritanos de Dios!

http://wilberbeast.com/2011/05/31/compositecollection-binding-problem/#comment-2337

En referencia a este error guarrero que da si no enlazas con la CollectionViewSource:

Cannot find governing FrameworkElement or FrameworkContentElement for target element. BindingExpression:Path=FilterOptions; DataItem=null; target element is ‘CollectionContainer’ (HashCode=23627591); target property is ‘Collection’ (type ‘IEnumerable’)

¡Buen provecho, y una patada en el pecho!

Messenger en MVVM Light? ¡Cuidado con los mensajitos!

Si una vista coge un mensaje y luego se cierra, DESREGISTRA LA VISTA! porque si no lo haces, se queda recibiendo mensajines everytime Risa y es muy muy jodido de encontrar la razón.

Aquí está lo que hay que hacer, fiery man:

public NewDocumentDialog()

       {

           InitializeComponent();

           Unloaded += (sender, args) => Messenger.Default.Unregister<QDFPage>(this);

 

           Messenger.Default.Register<QDFPage>(this, OnMessageReceived);   

       }

 

       private void OnMessageReceived(QDFPage page)

       {

           SetPage(page);

           DialogResult = true;

       }

 

Y esto de más abajo es la respuesta que no me han dejado publicar en StackOverflow… que quede aquí reflejada: http://stackoverflow.com/questions/7036873/when-to-dispose-viewmodel-in-mvvm-light

Thanks, thanks a lot! I was using a widow with ShowDialog. This view has a viewmodel that communicates success using the Messenger. When opened the second time, when setting the DialogResult = true, it stated “DialogResult can be set only after Window is created and shown as dialog.”

The fact is that I the older instances of the window didn’t unregister from the Messenger! They were still receiving messages! show the attempts to set their DialogResult failed, logically.

It was hard to find, but it’s FIXED!

EventToCommand

 

<i:Interaction.Triggers>

       <i:EventTrigger EventName="MouseEnter">

           <cmd:EventToCommand Command="{Binding TestCommand,

                                         Mode=OneWay}"

              CommandParameter="{Binding Text,

                                 ElementName=MyTextBox,

                                 Mode=OneWay}"

              MustToggleIsEnabledValue="True" />

       </i:EventTrigger>

   </i:Interaction.Triggers>