Pergunta

I am building a WPF desktop application built on the MVVM pattern.

I want to display a number of graphs, and have decided on the old ZedGraph library, as I am familiar with it and there does not seem to be a better option available at the moment (please comment if there is)

I can put the graph control on my View with the following code:

    <WindowsFormsHost>
        <zed:ZedGraphControl x:Name="graphControl"/>
    </WindowsFormsHost>

However, I want to manipulate the graph control quite a bit, setting the axes and the data etc etc. Sticking to MVVM, I can't call the graph control from the ViewModel, and I don't want to put graph manipulation in the View's code behind.

Is there a way to put the Graph Control object in the ViewModel, manipulate it there, and still have the View display it?

Foi útil?

Solução

IMO, I think it is not possible, since the underlying control which you make use is a Windows Forms control. So as a workaround, you could write a Custom WPF Control, which merely wraps Graph control using WindowsFormsHost approach and exposes the much needed properties to manipulate axes, data, etc.

Outras dicas

To host ZedGraph in WPF window, look at the example here.

It's quite possible. You can use the Behaviors pattern to manipulate the graph. Set up dependency properties that can be used as bindings in the XAML to your view model. Then the code in your Behaviors (the dependency properties) then acts as the glue between your bindings in the xaml and the actual control.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top