user3610920
user3610920

Reputation: 1652

Command binding in WPF MVM

I have a WPF project. In that I have 3 views and one viewmodel.

1.View 1.Xaml, View1viewmodel.cs 2.View 2.Xaml 3.View 3.Xaml

View 3 is referred in view 2 like below

<ScrollViewer>
    <local:FeatureView x:Name="View3" Margin="0,5,5,0" Visibility="{Binding 
        IsFeatureView,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" />
</ScrollViewer> 

and View2 is referred in view 1 like below

<StackPanel>
    <local:ProjectConfigurations x:Name="View2" />
<StackPanel/>

Datacontext in defined in View1

<Window.DataContext>
    <local:View1ViewModel />
</Window.DataContext>

now i need to command bind a check box control of View 3. the property is defined in View1ViewModel.but am unable to achieve that, please any one guide me to achieve this

Upvotes: 1

Views: 527

Answers (1)

Sheridan
Sheridan

Reputation: 69987

You just need to use a RelativeSource Binding to access the property from the view model.

In view 3:

<Checkbox Content="{Binding DataContext.PropertyInViewModel, 
    RelativeSource={RelativeSource AncestorType={x:Type YourPrefix:View1}}}"

Upvotes: 1

Related Questions