In wpf mvvm mode, i have a usercontrol like this
<UserControl MyControl>
<Grid>
<DataGrid
ItemsSource="{Binding MySource}"
Visibility = "{Binding the usercontrol's datacontext.UserGrade}"
/>
</Grid>
</UserControl>
In my MainPageView I use it like this
<Window:MainPageView
xmlns:vm="clr-namespace:My.ViewModel"
xmlns:userCtl="clr-namespace:My.Controls"
<Window.DataContext>
<vm:MainPageViewModel/>
</Window.DataContext>
<userCtl:MyControl>
<userCtl:Mycontrol.DataContext>
<vm:MyControlViewModel/>
</userCtl:Mycontrol.DataContext>
<userCtl:MyControl>
</Window:MainPageView>
Now here's the question, how can I access the MyUserControl's datacontext.UserVisiable, and binding to the MyUserControl's datagrid visibility? I tried to use {RelativeSource FindAncestor, AncestorType={x:Type UserControl}} but it did not work, or I didi it wrong? Thanks!
Window
, but usingUserControl
type inFindAncestor
... why? – Sinatr