Skip to content

Commit b02a080

Browse files

33 files changed

+3149
-0
lines changed

DataVirtualization.sln

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 10.00
3+
# Visual Studio 2008
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataVirtualization", "DataVirtualization\DataVirtualization.csproj", "{48E0EB7C-30B3-4A98-89BC-732039BEF625}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataVirtualizationDemo", "DataVirtualizationDemo\DataVirtualizationDemo.csproj", "{722DDA67-EA49-4A83-BC07-0739C1A608A5}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{48E0EB7C-30B3-4A98-89BC-732039BEF625}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{48E0EB7C-30B3-4A98-89BC-732039BEF625}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{48E0EB7C-30B3-4A98-89BC-732039BEF625}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{48E0EB7C-30B3-4A98-89BC-732039BEF625}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{722DDA67-EA49-4A83-BC07-0739C1A608A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{722DDA67-EA49-4A83-BC07-0739C1A608A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{722DDA67-EA49-4A83-BC07-0739C1A608A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{722DDA67-EA49-4A83-BC07-0739C1A608A5}.Release|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
EndGlobal

DataVirtualization.suo

27.5 KB
Binary file not shown.
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Windows;
4+
using System.Windows.Controls;
5+
using System.Windows.Documents;
6+
using System.Windows.Media;
7+
8+
namespace DevZest.Windows.DataVirtualization
9+
{
10+
partial class AdornerManager
11+
{
12+
private class DecoratorAdorner : Adorner
13+
{
14+
private UIElement _child;
15+
private AdornerLayer _adornerLayer;
16+
17+
public DecoratorAdorner(FrameworkElement source, DataTemplate adorner)
18+
: base(source)
19+
{
20+
Debug.Assert(source != null);
21+
Debug.Assert(adorner != null);
22+
ContentPresenter contentPresenter = new ContentPresenter();
23+
contentPresenter.Content = source;
24+
contentPresenter.ContentTemplate = adorner;
25+
_child = contentPresenter;
26+
AddLogicalChild(_child);
27+
AddVisualChild(_child);
28+
}
29+
30+
public DecoratorAdorner(FrameworkElement source, UIElement adorner)
31+
: base(source)
32+
{
33+
DataContext = source;
34+
_child = adorner;
35+
AddVisualChild(_child);
36+
}
37+
38+
private FrameworkElement Source
39+
{
40+
get { return AdornedElement as FrameworkElement; }
41+
}
42+
43+
protected override Size ArrangeOverride(Size finalSize)
44+
{
45+
_child.Arrange(new Rect(new Point(), finalSize));
46+
return finalSize;
47+
}
48+
49+
protected override Visual GetVisualChild(int index)
50+
{
51+
if (index != 0)
52+
throw new ArgumentOutOfRangeException("index");
53+
return _child;
54+
}
55+
56+
protected override int VisualChildrenCount
57+
{
58+
get { return 1; }
59+
}
60+
61+
public void Show()
62+
{
63+
Debug.Assert(_adornerLayer == null);
64+
65+
if (!Source.IsLoaded)
66+
Source.Loaded += new RoutedEventHandler(OnLoaded);
67+
else
68+
AddToAdornerLayer();
69+
}
70+
71+
private void OnLoaded(object sender, RoutedEventArgs e)
72+
{
73+
Source.Loaded -= new RoutedEventHandler(OnLoaded);
74+
AddToAdornerLayer();
75+
}
76+
77+
private void AddToAdornerLayer()
78+
{
79+
_adornerLayer = AdornerLayer.GetAdornerLayer(AdornedElement);
80+
if (_adornerLayer != null)
81+
_adornerLayer.Add(this);
82+
}
83+
84+
public void Close()
85+
{
86+
Source.Loaded -= new RoutedEventHandler(OnLoaded);
87+
if (_adornerLayer != null)
88+
{
89+
_adornerLayer.Remove(this);
90+
_adornerLayer = null;
91+
}
92+
}
93+
}
94+
}
95+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Diagnostics.CodeAnalysis;
4+
using System.Windows;
5+
using System.Windows.Controls;
6+
using System.Windows.Documents;
7+
8+
namespace DevZest.Windows.DataVirtualization
9+
{
10+
/// <summary>Provides attached properties to get or set a <see cref="UIElement"/> or <see cref="DataTemplate"/> as the adorner of
11+
/// <see cref="FrameworkElement"/>.</summary>
12+
/// <remarks><para><see cref="AdornerManager"/> provides two attached properties: <b>Adorner</b> to get or set <see cref="UIElement"/>
13+
/// as adorner of <see cref="FrameworkElement"/>; and <b>AdornerTemplate</b> to get or set <see cref="DataTemplate"/>
14+
/// as adorner of <see cref="FrameworkElement"/>. You can use these attached properties to declare adorner of
15+
/// <see cref="FrameworkElement"/> in XAML.</para>
16+
/// <para><b>AdornerTemplate</b> provides similar functionality as <b>Adorner</b>, however it can be used in style setters because
17+
/// direct UI child is not allowed. Both way the provided adorner inherits DataContext as adorned element.</para>
18+
/// <para>Setting adorner for specified <see cref="FrameworkElement"/> will clear the adorner previously set, no matter using
19+
/// <b>Adorner</b> or <b>AdornerTemplate</b> attached properties.</para></remarks>
20+
/// <example>The following example demostrates the usage of <b>Adorner</b> and <b>AdornerTemplate</b> attached property:
21+
/// <code lang="xaml" source="..\Samples\Common\CSharp\AdornerManagerSample\Window1.xaml" />
22+
/// </example>
23+
static partial class AdornerManager
24+
{
25+
/// <summary>Identifies the <b>Adorner</b> attached property.</summary>
26+
public static readonly DependencyProperty AdornerProperty = DependencyProperty.RegisterAttached("Adorner", typeof(UIElement), typeof(AdornerManager),
27+
new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnAdornerChanged)));
28+
/// <summary>Identifies the <b>AdornerTemplate</b> attached property.</summary>
29+
public static readonly DependencyProperty AdornerTemplateProperty = DependencyProperty.RegisterAttached("AdornerTemplate", typeof(DataTemplate), typeof(AdornerManager),
30+
new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnAdornerChanged)));
31+
private static readonly DependencyPropertyKey DecoratorAdornerPropertyKey = DependencyProperty.RegisterAttachedReadOnly("DecoratorAdorner", typeof(DecoratorAdorner), typeof(AdornerManager),
32+
new FrameworkPropertyMetadata(null));
33+
34+
private static void OnAdornerChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
35+
{
36+
FrameworkElement element = d as FrameworkElement;
37+
if (element == null)
38+
return;
39+
40+
DecoratorAdorner oldDecorator = GetDecoratorAdorner(element);
41+
DecoratorAdorner newDecorator = GetNewDecorator(element, e.NewValue);
42+
SetDecoratorAdorner(element, newDecorator);
43+
if (oldDecorator != null)
44+
oldDecorator.Close();
45+
if (newDecorator != null)
46+
newDecorator.Show();
47+
}
48+
49+
private static DecoratorAdorner GetNewDecorator(FrameworkElement element, object newValue)
50+
{
51+
DataTemplate newTemplate = newValue as DataTemplate;
52+
if (newTemplate != null)
53+
return new DecoratorAdorner(element, newTemplate);
54+
55+
UIElement newUIElement = newValue as UIElement;
56+
if (newUIElement != null)
57+
return new DecoratorAdorner(element, newUIElement);
58+
59+
return null;
60+
}
61+
62+
/// <summary>Gets the adorner <see cref="UIElement"/> for specified <see cref="FrameworkElement"/>.
63+
/// Getter of <b>Adorner</b> attached property.</summary>
64+
/// <param name="element">The specified <see cref="FrameworkElement"/>.</param>
65+
/// <returns>The adorner <see cref="UIElement" />.</returns>
66+
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
67+
public static UIElement GetAdorner(FrameworkElement element)
68+
{
69+
return (UIElement)element.GetValue(AdornerProperty);
70+
}
71+
72+
/// <summary>Sets the adorner <see cref="UIElement"/> for specified <see cref="FrameworkElement"/>.
73+
/// Setter of <b>Adorner</b> attached property.</summary>
74+
/// <param name="element">The specified <see cref="FrameworkElement"/>.</param>
75+
/// <param name="value">The adorner <see cref="UIElement"/> to set.</param>
76+
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
77+
public static void SetAdorner(FrameworkElement element, UIElement value)
78+
{
79+
element.SetValue(AdornerProperty, value);
80+
}
81+
82+
/// <summary>Gets the adorner <see cref="DataTemplate"/> for specified <see cref="FrameworkElement"/>.
83+
/// Getter of <b>AdornerTemplate</b> attached property.</summary>
84+
/// <param name="element">The specified <see cref="FrameworkElement"/>.</param>
85+
/// <returns>The adorner <see cref="DataTemplate" />.</returns>
86+
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
87+
public static DataTemplate GetAdornerTemplate(FrameworkElement element)
88+
{
89+
return (DataTemplate)element.GetValue(AdornerTemplateProperty);
90+
}
91+
92+
/// <summary>Sets the adorner <see cref="DataTemplate"/> for specified <see cref="FrameworkElement"/>.
93+
/// Setter of <b>AdornerTemplate</b> attached property.</summary>
94+
/// <param name="element">The specified <see cref="FrameworkElement"/>.</param>
95+
/// <param name="value">The adorner <see cref="DataTemplate"/> to set.</param>
96+
[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
97+
public static void SetAdornerTemplate(FrameworkElement element, DataTemplate value)
98+
{
99+
element.SetValue(AdornerTemplateProperty, value);
100+
}
101+
102+
private static DecoratorAdorner GetDecoratorAdorner(DependencyObject element)
103+
{
104+
return (DecoratorAdorner)element.GetValue(DecoratorAdornerPropertyKey.DependencyProperty);
105+
}
106+
107+
private static void SetDecoratorAdorner(DependencyObject element, DecoratorAdorner value)
108+
{
109+
element.SetValue(DecoratorAdornerPropertyKey, value);
110+
}
111+
}
112+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6+
<ProductVersion>9.0.30729</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{48E0EB7C-30B3-4A98-89BC-732039BEF625}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>DevZest.Windows.DataVirtualization</RootNamespace>
12+
<AssemblyName>DevZest.DataVirtualization</AssemblyName>
13+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
14+
<FileAlignment>512</FileAlignment>
15+
<SignAssembly>true</SignAssembly>
16+
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
17+
</PropertyGroup>
18+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>bin\Debug\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
</PropertyGroup>
27+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
28+
<DebugType>pdbonly</DebugType>
29+
<Optimize>true</Optimize>
30+
<OutputPath>bin\Release\</OutputPath>
31+
<DefineConstants>TRACE</DefineConstants>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="PresentationCore">
37+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
38+
</Reference>
39+
<Reference Include="PresentationFramework">
40+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
41+
</Reference>
42+
<Reference Include="System" />
43+
<Reference Include="System.Core">
44+
<RequiredTargetFramework>3.5</RequiredTargetFramework>
45+
</Reference>
46+
<Reference Include="WindowsBase">
47+
<RequiredTargetFramework>3.0</RequiredTargetFramework>
48+
</Reference>
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Compile Include="AdornerManager.cs" />
52+
<Compile Include="AdornerManager.DecoratorAdorner.cs" />
53+
<Compile Include="GridViewSort.cs" />
54+
<Compile Include="IVirtualListLoader.cs" />
55+
<Compile Include="LoadingAnimation.xaml.cs">
56+
<DependentUpon>LoadingAnimation.xaml</DependentUpon>
57+
</Compile>
58+
<Compile Include="LoadingAnimationBlock.xaml.cs">
59+
<DependentUpon>LoadingAnimationBlock.xaml</DependentUpon>
60+
</Compile>
61+
<Compile Include="Properties\AssemblyInfo.cs" />
62+
<Compile Include="QueuedBackgroundWorker.cs" />
63+
<Compile Include="SortOrder.cs" />
64+
<Compile Include="VirtualList.cs" />
65+
<Compile Include="VirtualList.ICollectionView.cs" />
66+
<Compile Include="VirtualListItem.cs" />
67+
<Compile Include="VirtualListItemBase.cs" />
68+
<Compile Include="VirtualListLoadingIndicator.cs" />
69+
</ItemGroup>
70+
<ItemGroup>
71+
<Page Include="LoadingAnimation.xaml">
72+
<Generator>MSBuild:Compile</Generator>
73+
<SubType>Designer</SubType>
74+
</Page>
75+
<Page Include="LoadingAnimationBlock.xaml">
76+
<Generator>MSBuild:Compile</Generator>
77+
<SubType>Designer</SubType>
78+
</Page>
79+
<Page Include="Themes\Generic.xaml">
80+
<Generator>MSBuild:Compile</Generator>
81+
<SubType>Designer</SubType>
82+
</Page>
83+
</ItemGroup>
84+
<ItemGroup>
85+
<None Include="Key.snk" />
86+
</ItemGroup>
87+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
88+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
89+
Other similar extension points exist, see Microsoft.Common.targets.
90+
<Target Name="BeforeBuild">
91+
</Target>
92+
<Target Name="AfterBuild">
93+
</Target>
94+
-->
95+
</Project>

0 commit comments

Comments
 (0)