Frage

In our project we are using GraphSharp library. We have encountered some problems when we wanted to remove all edges and vertices from graph.

In every example there is, in xaml there is something like that

<zoom:ZoomControl  Grid.Row="1"  Zoom="0.2" ZoomBoxOpacity="0.5" Background="#ff656565">

                    <toProjectGraph:EntityGraphLayout x:Name="graphLayout" Margin="10"
                    Graph="{Binding Path=GraphViewModel.EntityGraph}"
                    LayoutAlgorithmType="{Binding Path=GraphViewModel.LayoutAlgorithmType, Mode=OneWay}"
                    OverlapRemovalAlgorithmType="FSA"
                    HighlightAlgorithmType="Simple" 
                      />
                </zoom:ZoomControl>

xaml creates instance of our class EntityGraphLayout and uses it to visualize everything.

Is it possible in some way to "bind" this instance of EntityGraphLayout to some property in our view model so we can reference it in our view model code?

Or maybe there is a way that we can create instance of this class and tell xaml to get referebce to object from some path.

War es hilfreich?

Lösung

Sounds like what you want is to create the object in your viewmodel, expose it as a property, and bind it to the Content property of your zoom control, something like this:

viewmodel:

public class ViewModel {
    private EntityGraphLayout _layout = new EntityGraphLayout();
    public EntityGraphLayout EntityGraphLayoutProperty
    { 
        get { return _layout; } 
        set { _layout = value; }
    }
}

XAML:

<zoom:ZoomControl Content="{Binding EntityGraphLayoutProperty}" Grid.Row="1"  Zoom="0.2" ZoomBoxOpacity="0.5" Background="#ff656565" >
</zoom:ZoomControl>

Note that you will need to make sure the DataContext for the zoom control is set to your viewmodel.

If you want it created in XAML, you could also access the object in your viewmodel by referring to it by the graphLayout name you defined in the XAML. This would require a reference to the view in your viewmodel, which may not be ideal.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top