I am trying to bind two properties from different classes in DataTemplate.
<DataTemplate x:Key="DemoItemTemplate" x:DataType="local:DemoInfo">
<NavigationViewItem Visibility="{Binding Visibility, Mode=TwoWay}" Content="{x:Bind Name}"/>
</DataTemplate>
DataType
set as DemoInfo
for this DataTemplate
and Name
value updated from DemoInfo
.
I have tried view model as source and relative source binding. But Visibility
property binding not working from ViewModel
class. Any suggest how to achieve this?
Visibility="{Binding Visibility, Source={StaticResource viewModel}}"
I could be wrong, but I thought the
Visibility
property had a dedicated enum that contains all the possible options (Visibility Enum) for theVisibility
property. So, your binding might be working just fine, but theType
of the bound property would need to be of typeVisibility
usingSystem.Windows
.On a side note, I wouldn't put a visibility property in the view model anyway. I think a more standard approach would be to have a visibility
DependencyProperty
in the immediate code behind of the view for your binding.