Starting off with a classic datatemplate:
<DataTemplate x:Key="RegularTemplate">
<Grid>
...
</Grid>
</DataTemplate>
assume the ViewModel object that is being rendered using the above template has the following property:
private Visibility _Visibility;
public Visibility VMVisibility
{
set
{
if (value == _Visibility) return;
_Visibility = value;
if (value == System.Windows.Visibility.Visible)
{
ViewRefresher.TwentySecondsTick += Tick;
}
else
{
ViewRefresher.TwentySecondsTick -= Tick;
}
}
private get
{
return _Visibility;
}
}
I want that setter code to somehow run when the listboxitem is not rendered by the panel containing it. It's a custom panel that hides/shows items during scrolling, so I just need to bind to the listboxitems's visibility somehow.
I've tried stuff along the lines of:
<DataTemplate x:Key="RegularTemplate">
<Grid>
...
</Grid>
<DataTrigger Binding="{Binding IsVisible,RelativeSource=
{RelativeSource FindAncestor,
AncestorType={x:Type ListBoxItem}}}" Value="False">
<Setter Property="{Binding VMVisibility}" Value="False"/>
</DataTrigger>
</DataTemplate>
but you can't use datatriggers that way.
Any ideas?