版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
第WPF使用WrapPanel實現(xiàn)虛擬化效果3.項目使用MIT開源許可協(xié)議;
4.眾所周知WPF的StackPanel在加載大量數(shù)據(jù)時性能會特別差,但是官方提供了一個虛擬化容器VirtualizingStackPanel;
VirtualizingStackPanel.IsVirtualizing附加屬性設(shè)置為true時就開啟虛擬化。VirtualizingStackPanel.IsVirtualizing附加屬性設(shè)置為false其VirtualizingStackPanel行為與普通StackPanel屬性的行為相同。
5.WrapPanel默認是不支持虛擬化的,所以需要自行實現(xiàn)。
1)VirtualizingWrapPanel查看源碼|VirtualizingWrapPanel查看源碼。
2)準備數(shù)據(jù)HospitalList.cs如下:
using
System;
using
System.Collections.Generic;
using
System.Collections.ObjectModel;
using
System.Windows.Media;
namespace
WPFDevelopers.Minimal.Sample.Models
public
class
HospitalList
:
ObservableCollectionHospital
{
public
HospitalList()
{
var
hospitals
=
new
string[]
{
"No.
189,
Grove
St,
Los
Angeles",
"No.
3669,
Grove
St,
Los
Angeles"
};
var
names
=
new
string[]
{
"Doctor
Fang",
"Judge
Qu"
};
var
images
=
new
string[]
{
"/80/v2-0711e97955adc9be9fbcff67e1007535_720w.jpg",
//"/80/v2-5b7f84c63075ba9771f6e6dc29a54615_720w.jpg",
"/80/v2-a3d6d8832090520e7ed6c748a8698e4e_720w.jpg",
"/80/v2-de7554ac9667a59255fe002bb8753ab6_720w.jpg"
};
var
state
=
0;
for
(var
i
=
1;
i
10000;
i++)
{
Add(new
Hospital
{
Id
=
$"9999{i}",
DoctorName
=
i
%
2
==
0
names[0]:names[1],
HospitalName
=
i
%
2
==
0
hospitals[0]
:
hospitals[1]
,State
=
state
,UserImage
=
images[state]
});
state++;
if
(state
2)
state
=
0;
}
}
}
public
class
Hospital
{
public
string
Id
{
get;
set;
}
public
string
DoctorName
{
get;
set;
}
public
string
HospitalName
{
get;
set;
}
public
string
UserImage
{
get;
set;
}
public
int
State
{
get;
set;
}
}
3)新建展示VirtualizingWrapPanelExample.xaml如下:
ws:Window
x:
xmlns="/winfx/2006/xaml/presentation"
xmlns:x="/winfx/2006/xaml"
xmlns:d="/expression/blend/2008"
xmlns:mc="/markup-compatibility/2006"
xmlns:ws="/WPFDevelopersOrg/WPFDevelopers.Minimal"
xmlns:local="clr-namespace:WPFDevelopers.Minimal.Sample.ExampleViews"
xmlns:model="clr-namespace:WPFDevelopers.Minimal.Sample.Models"
xmlns:converts="clr-namespace:WPFDevelopers.Minimal.Sample.Converts"
mc:Ignorable="d"
WindowStartupLocation="CenterScreen"
Title="System
V1.0"
Height="450"
Width="900"
Window.Resources
model:HospitalList
x:Key="myHospitalList"/
converts:StateConvert
x:Key="stateConvert"/converts:StateConvert
/Window.Resources
Grid
Margin="4"
WrapPanel
HorizontalAlignment="Left"
WrapPanel.Resources
Style
TargetType="Border"
Setter
Property="Padding"
Value="2"/Setter
Setter
Property="BorderThickness"
Value="1"/Setter
/Style
Style
TargetType="Rectangle"
Setter
Property="Width"
Value="15"/Setter
Setter
Property="Height"
Value="15"/Setter
Setter
Property="Opacity"
Value=".2"/Setter
/Style
/WrapPanel.Resources
WrapPanel
Border
BorderBrush="Green"
Rectangle
Fill="Green"/
/Border
TextBlock
Text="Idle"
Foreground="Black"
Margin="4,0"/
/WrapPanel
WrapPanel
Border
BorderBrush="Orange"
Rectangle
Fill="Orange"/
/Border
TextBlock
Text="Slightly
Idle"
Foreground="Black"
Margin="4,0"/
/WrapPanel
WrapPanel
Border
BorderBrush="Red"
Rectangle
Fill="Red"/
/Border
TextBlock
Text="Busy"
Foreground="Black"
Margin="4,0"/
/WrapPanel
/WrapPanel
TextBlock
HorizontalAlignment="Right"
Foreground="Black"
Margin="4,2"
FontSize="16"
Run
Text="Count:"/Run
Run
Text="{Binding
ElementName=DocumentsList,Path=.Items.Count,Mode=OneTime}"/Run
/TextBlock
ListBox
x:Name="DocumentsList"
ItemsSource="{Binding
Source={StaticResource
myHospitalList}}"
Margin="0,24,0,0"
ListBox.ItemTemplate
DataTemplate
Border
BorderBrush="{Binding
State,Converter={StaticResource
stateConvert}}"
BorderThickness="1"
Width="196"
Height="94"
Grid
Grid.ColumnDefinitions
ColumnDefinition/
ColumnDefinition/
/Grid.ColumnDefinitions
Grid.RowDefinitions
RowDefinition/
RowDefinition/
RowDefinition/
/Grid.RowDefinitions
Rectangle
Fill="{Binding
State,Converter={StaticResource
stateConvert}}"
Opacity=".2"
Grid.ColumnSpan="2"
Grid.RowSpan="3"/
Border
Grid.RowSpan="2"
Grid.Column="0"
Width="60"
Height="60"
Margin="0,4,0,0"
CornerRadius="10"
Border.Background
ImageBrush
ImageSource="{Binding
UserImage}"
Stretch="Uniform"/
/Border.Background
/Border
TextBlock
Grid.Column="1"
Grid.Row="0"
Text="{Binding
Path=Id}"
Margin="0,4,0,0"/
TextBlock
Grid.Column="1"
Grid.Row="1"
Text="{Binding
Path=DoctorName}"/
TextBlock
Grid.ColumnSpan="2"
Grid.Row="2"
Padding="10,0"
Text="{Binding
Path=HospitalName}"
TextTrimming="CharacterEllipsis"/
/Grid
/Border
/DataTemplate
/ListBox.ItemTemplate
ListBox.Template
ControlTemplate
Border
CornerRadius="2"
BorderBrush="{TemplateBinding
BorderBrush}"
BorderThickness="{TemplateBinding
BorderThickness}"
ScrollViewer
x:Name="ScrollViewer"
Padding="{TemplateBinding
Padding}"
Background="{TemplateBinding
Background}"
BorderBrush="Transparent"
BorderThickness="0"
IsTabStop="False"
ItemsPresenter
/
/ScrollViewer
/Border
/ControlTemplate
/ListBox.Template
ListBox.ItemsPanel
ItemsPanelTemplate
ws:VirtualizingWrapPanel
ItemWidth="200"
ItemHeight="100"/
/ItemsPanelTemplate
/ListBox.ItemsPanel
/ListBox
/Grid
/ws:Window
4)狀態(tài)StateConvert.cs如下:
using
System;
using
System.Windows.Data;
using
System.Windows.Media;
namespace
WPFDevelopers.Minimal.Sample.Converts
public
class
StateConvert
:
IValueConverter
{
public
object
Convert(object
value,
Type
targetType,
o
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 外勤機械工復(fù)試考核試卷含答案
- 刨插工安全培訓(xùn)效果評優(yōu)考核試卷含答案
- 玻璃制品手工成型工安全宣傳強化考核試卷含答案
- 海鹽采收工班組建設(shè)競賽考核試卷含答案
- 絞車操作工安全素養(yǎng)競賽考核試卷含答案
- 磚瓦生產(chǎn)工安全素養(yǎng)測試考核試卷含答案
- 海南房產(chǎn)中介培訓(xùn)課程
- 酒店員工培訓(xùn)計劃實施與跟蹤制度
- 酒店客房用品更換與補給制度
- 超市員工培訓(xùn)及業(yè)務(wù)知識制度
- 音樂場所衛(wèi)生管理制度
- 2026云南昭通市搬遷安置局招聘公益性崗位人員3人備考題庫及答案詳解(考點梳理)
- 標(biāo)書財務(wù)制度
- 四川發(fā)展控股有限責(zé)任公司會計崗筆試題
- 2026中國電信四川公用信息產(chǎn)業(yè)有限責(zé)任公司社會成熟人才招聘備考題庫及一套答案詳解
- 2025-2030心理健康行業(yè)市場發(fā)展分析及趨勢前景與投資戰(zhàn)略研究報告
- 技術(shù)副總年終總結(jié)
- 《馬年馬上有錢》少兒美術(shù)教育繪畫課件創(chuàng)意教程教案
- 天津市專升本高等數(shù)學(xué)歷年真題(2016-2025)
- 2025山西焦煤集團所屬華晉焦煤井下操作技能崗?fù)艘圮娙苏衅?0人筆試參考題庫帶答案解析
- 兒童骨科主任論兒童骨科
評論
0/150
提交評論