Created
February 3, 2011 09:50
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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