Skip to content

Instantly share code, notes, and snippets.

@robfe
Created February 3, 2011 09:50
Show Gist options
  • Save robfe/809281 to your computer and use it in GitHub Desktop.
Save robfe/809281 to your computer and use it in GitHub Desktop.
Helps you to keep the number of visuals in your visual tree down
/// <summary>
/// Easy way to switch between no content template and some content template in silverlight
/// Helps you to keep the number of visuals in your visual tree down.
/// </summary>
public class VirtualContentPresenter : ContentPresenter
{
public static readonly DependencyProperty VirtualContentTemplateProperty = DependencyProperty.Register("VirtualContentTemplate",
typeof(DataTemplate),
typeof(VirtualContentPresenter),
new PropertyMetadata(null, (o, args) => ((VirtualContentPresenter) o).VirtualContentPropertyChanged()));
public static readonly DependencyProperty ShowVirtualContentProperty = DependencyProperty.Register("ShowVirtualContent",
typeof(bool),
typeof(VirtualContentPresenter),
new PropertyMetadata(false, (o, args) => ((VirtualContentPresenter) o).VirtualContentPropertyChanged()));
public DataTemplate VirtualContentTemplate
{
get { return (DataTemplate)GetValue(VirtualContentTemplateProperty); }
set { SetValue(VirtualContentTemplateProperty, value); }
}
public bool ShowVirtualContent
{
get { return (bool)GetValue(ShowVirtualContentProperty); }
set { SetValue(ShowVirtualContentProperty, value); }
}
void VirtualContentPropertyChanged()
{
ContentTemplate = ShowVirtualContent ? VirtualContentTemplate : null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment