heltonbiker
heltonbiker

Reputation: 27575

Instantiate ViewModel property as element in XAML

I have a ViewModel with MyGeometry property of type Geometry.

In XAML View, I have a GeometryGroup.

I would like the following:

<GeometryGroup>
    <EllipseGeometry ... />
    <RectangleGeometry ... />
    <!-- How can I put `MyGeometry` here?
     I'm pretty sure I've seen something similar before -->
</GeometryGroup>

So, the broad question is: How can I instantiate some viewmodel property directly in XAML as a "standalone" element, instead of binding it to some other element's property? (if at all possible, of course)

Upvotes: 0

Views: 80

Answers (2)

Clemens
Clemens

Reputation: 128060

Not really nice, but works:

<GeometryGroup>
    <EllipseGeometry ... />
    <RectangleGeometry ... />
    <CombinedGeometry Geometry1="{Binding MyGeometry}"/>
</GeometryGroup>

Upvotes: 2

Hamlet Hakobyan
Hamlet Hakobyan

Reputation: 33381

I think the correct approach is:

<GeometryGroup>
    <EllipseGeometry ... />
    <RectangleGeometry ... />
    <MyGeometry Prop1="{Binding Prop1_InViewModel}" Prop2="{Binding Prop2_InViewModel}" ... />
</GeometryGroup>

Where Prop1_InViewModel and Prop2_InViewModel are properties of your ViewModel.

Upvotes: 0

Related Questions