I have a DataTemplate:
<DataTemplate x:Key="BMSelectedItemTemplate">
<StackPanel Orientation="Horizontal">
<TextBlock Text="*" Visibility=???/>
<TextBlock Text="{Binding Name}"/>
</StackPanel>
</DataTemplate>
I have a DataTemplateSelector using the above template:
<BookmarkItemDataTemplateSelector x:Key="BookmarkItemDataTemplateSelector" SelectedItemTemplate="{StaticResource BMSelectedItemTemplate}"
DropdownItemsTemplate="{StaticResource BMDropdownItemTemplate}" />
I use the above data template selector in a comboBox:
<StackPanel x:Name="splBookmark" Visibility="{Binding ShowBookmark, Converter={StaticResource BooleanToVisibilityConverter}}">
<ComboBox x:Name="cbBookmark" ItemTemplateSelector="{StaticResource BookmarkItemDataTemplateSelector}"/>
</StackPanel>
My view model has properties ShowBookmark and ShowAsterisk. I want to bind visibility of the "*" in BMSelectedItemTemplate to my view model's property ShowAsterisk. How could I do that? I tried:
Visibility="{Binding ShowAsterisk, Converter={StaticResource BooleanToVisibilityConverter}}"
But it didn't work, it said data template cannot find property ShowAsterisk, I think this makes sense, because the data template is binding to a list of MBookmark objects, and in my MBookmark class, there is no property of ShowAsterisk. ShowAsterisk is a property of the view model which is binding to splBookmark stack panel.
My question is how to bind ancestor element's view model property to my data template element's visibility?
I cannot use relative path ancestor type to find my comboBox or stack panel, it seems I can only use self or TemplateParent in my relative source. I use silverlight.
Thank you!