Coder Social home page Coder Social logo

Comments (4)

ReedCopsey avatar ReedCopsey commented on June 25, 2024

@ruxo The EventValueCommand is meant to be used where the CommandParameter is of the generic type of the Event type. In this case, it'd mean you'd need a converter to pass the parameter of type MainWindowEvents.

What are you trying to do? There are a couple of approaches -

  1. You could use the normal command infrastructure from ViewModelBase to just create a command that accepts a string parameter, then optionally add it to your event stream if you need at that point.
  2. Write a converter to convert from your actual parameter type to the event type. This is what the sample applications in FsXaml all do.

from fsharp.viewmodule.

ruxo avatar ruxo commented on June 25, 2024

I'm interested in Event Stream and trying to do MVC with it (inspired by a blog post from http://marisks.net/). In my real XAML, there is also a TreeView which I also uses for selecting item. The TreeViewItem uses EventToCommand to convert Selected event to MainWindowEvents. Like following snippet:

      <TreeViewItem Header="About sample" Tag="AboutDialog.xaml">
        <i:Interaction.Triggers><i:EventTrigger EventName="Selected"><fsx:EventToCommand Command="{Binding EventCommand}" EventArgsConverter="{StaticResource selectConverter}" /> </i:EventTrigger> </i:Interaction.Triggers>
      </TreeViewItem>

Now I'm trying to use buttons instead of the TreeView. I guess I can use EventTrigger to do the same thing but I'm curious if there is a shorter way to do so.

So I have to apply a converter. Do I have to implement it myself (something like EventArgsConverter) or is there already a helper in the library? Sorry I'm new to this library. Thank you for your help :)

from fsharp.viewmodule.

ReedCopsey avatar ReedCopsey commented on June 25, 2024

You'd need to make your own converter. If you inherit inherit EventViewModelBase<string>() instead of MainWindowEvents, using a string as the command parameter will work, though.

from fsharp.viewmodule.

ruxo avatar ruxo commented on June 25, 2024

Just post here for reference: http://stackoverflow.com/questions/335849/wpf-commandparameter-is-null-first-time-canexecute-is-called

So the true culprit is setting CommandParameter does not re-evaluate CanExecute method. Simple workaround is just swap the order of Command and CommandParameter in the XAML.

from fsharp.viewmodule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.