最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

WPF使用WrapPanel實(shí)現(xiàn)虛擬化效果

 更新時(shí)間:2022年09月19日 08:43:27   作者:驚鏵  
這篇文章主要為大家詳細(xì)介紹了如何利用WPF WrapPanel實(shí)現(xiàn)虛擬化效果,文中的示例代碼講解詳細(xì),對(duì)我們學(xué)習(xí)或工作有一定幫助,感興趣的小伙伴可以了解一下

WrapPanel 實(shí)現(xiàn)虛擬化

1.框架使用大于等于.NET40;

2.Visual Studio 2022;

3.項(xiàng)目使用 MIT 開(kāi)源許可協(xié)議;

4.眾所周知 WPF 的 StackPanel 在加載大量數(shù)據(jù)時(shí)性能會(huì)特別差,但是官方提供了一個(gè)虛擬化容器VirtualizingStackPanel

  • VirtualizingStackPanel.IsVirtualizing 附加屬性設(shè)置為 true時(shí)就開(kāi)啟虛擬化。
  • VirtualizingStackPanel.IsVirtualizing 附加屬性設(shè)置為 falseVirtualizingStackPanel行為與普通StackPanel屬性的行為相同。

5.WrapPanel 默認(rèn)是不支持虛擬化的,所以需要自行實(shí)現(xiàn)。

1) VirtualizingWrapPanel 查看源碼  |   VirtualizingWrapPanel 查看源碼。

2) 準(zhǔn)備數(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?:?ObservableCollection<Hospital>
????{
????????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[]?
????????????????{?"https://pic2.zhimg.com/80/v2-0711e97955adc9be9fbcff67e1007535_720w.jpg",
??????????????????//"https://pic2.zhimg.com/80/v2-5b7f84c63075ba9771f6e6dc29a54615_720w.jpg",
??????????????????"https://pic3.zhimg.com/80/v2-a3d6d8832090520e7ed6c748a8698e4e_720w.jpg",
??????????????????"https://pic3.zhimg.com/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:Class="WPFDevelopers.Minimal.Sample.ExampleViews.VirtualizingWrapPanelExample"
????????xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
????????xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
????????xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
????????xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
????????xmlns:ws="https://github.com/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,?object?parameter,?System.Globalization.CultureInfo?cultureInfo)
????????{
????????????var?color?=?Brushes.Green;
????????????if?(value?!=?null)
????????????{
????????????????var?state?=?int.Parse(value.ToString());
????????????????switch?(state)
????????????????{
????????????????????case?0:
????????????????????????color?=?Brushes.Green;
????????????????????????break;
????????????????????case?1:
????????????????????????color?=?Brushes.Orange;
????????????????????????break;
????????????????????case?2:
????????????????????????color?=?Brushes.Red;
????????????????????????break;
????????????????}
????????????}

????????????return?color;
????????}
????????public?object?ConvertBack(object?value,?Type?targetType,?object?parameter,?System.Globalization.CultureInfo?cultureInfo)
????????{
????????????throw?new?NotImplementedException();
????????}
????}
}

實(shí)現(xiàn)效果

到此這篇關(guān)于WPF使用WrapPanel實(shí)現(xiàn)虛擬化效果的文章就介紹到這了,更多相關(guān)WPF WrapPanel虛擬化內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Unity實(shí)現(xiàn)VR中在黑板上寫(xiě)字效果

    Unity實(shí)現(xiàn)VR中在黑板上寫(xiě)字效果

    這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)VR中在黑板上寫(xiě)字效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • C#實(shí)現(xiàn)判斷圖形文件格式的方法

    C#實(shí)現(xiàn)判斷圖形文件格式的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)判斷圖形文件格式的方法,包括常見(jiàn)的擴(kuò)展名判定及文件內(nèi)容判定等,非常實(shí)用,需要的朋友可以參考下
    2014-09-09
  • C#生成圖形驗(yàn)證碼的實(shí)現(xiàn)方式

    C#生成圖形驗(yàn)證碼的實(shí)現(xiàn)方式

    我們當(dāng)用戶登錄系統(tǒng)時(shí)經(jīng)常會(huì)用到圖形驗(yàn)證碼技術(shù),要求用戶識(shí)別圖片中的內(nèi)容,并正確輸入,方可嘗試登錄,因此,圖形驗(yàn)證碼是一個(gè)網(wǎng)絡(luò)安全技術(shù)手段,圖形驗(yàn)證碼的呈現(xiàn)形式有很多種,這里我們將介紹最基本的生成方式,感興趣的朋友可以參考下
    2024-04-04
  • C#使用SqlBulkCopy批量復(fù)制數(shù)據(jù)到數(shù)據(jù)表

    C#使用SqlBulkCopy批量復(fù)制數(shù)據(jù)到數(shù)據(jù)表

    這篇文章主要介紹了C#使用SqlBulkCopy批量復(fù)制數(shù)據(jù)到數(shù)據(jù)表的方法,較為詳細(xì)的講述了SqlBulkCopy批量復(fù)制數(shù)據(jù)到數(shù)據(jù)表的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2014-10-10
  • 使用C#實(shí)現(xiàn)一個(gè)PPT遙控器

    使用C#實(shí)現(xiàn)一個(gè)PPT遙控器

    由于本人需要參加的討論會(huì)比較多,每次都會(huì)涉及到PPT,有時(shí)候坐在電腦旁講會(huì)比較不生動(dòng),前人就發(fā)明了PPT遙控器,今天就給大家介紹下基于C#實(shí)現(xiàn)ppt遙控器,感興趣的朋友一起看看吧
    2021-05-05
  • C#實(shí)現(xiàn)將日志寫(xiě)入文本文件的方法

    C#實(shí)現(xiàn)將日志寫(xiě)入文本文件的方法

    這篇文章主要介紹了C#實(shí)現(xiàn)將日志寫(xiě)入文本文件的方法,涉及C#針對(duì)日志文件寫(xiě)入的相關(guān)技巧,需要的朋友可以參考下
    2015-05-05
  • C#實(shí)現(xiàn)優(yōu)先隊(duì)列和堆排序

    C#實(shí)現(xiàn)優(yōu)先隊(duì)列和堆排序

    本文詳細(xì)講解了C#實(shí)現(xiàn)優(yōu)先隊(duì)列和堆排序的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-04-04
  • C#通過(guò)委托調(diào)用Button單擊事件的方法

    C#通過(guò)委托調(diào)用Button單擊事件的方法

    本文給大家分享的是通過(guò)委托取消Button事件switch-case的方法,十分的簡(jiǎn)單實(shí)用,有需要的小伙伴可以參考下。
    2015-05-05
  • C#實(shí)現(xiàn)帶百分比的進(jìn)度條功能示例

    C#實(shí)現(xiàn)帶百分比的進(jìn)度條功能示例

    這篇文章主要介紹了C#實(shí)現(xiàn)帶百分比的進(jìn)度條功能,分析了帶百分比進(jìn)度條的功能需求并結(jié)合實(shí)例形式給出了具體實(shí)現(xiàn)步驟與相關(guān)操作方法,需要的朋友可以參考下
    2017-05-05
  • C#獲取ListView鼠標(biāo)下的Item實(shí)例

    C#獲取ListView鼠標(biāo)下的Item實(shí)例

    下面小編就為大家?guī)?lái)一篇C#獲取ListView鼠標(biāo)下的Item實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-01-01

最新評(píng)論

泾川县| 衡山县| 绥芬河市| 嵊州市| 麦盖提县| 湛江市| 石家庄市| 容城县| 山阳县| 利津县| 隆林| 大邑县| 白沙| 师宗县| 东方市| 阳山县| 彰武县| 治县。| 资源县| 文昌市| 岗巴县| 河北省| 饶河县| 卫辉市| 宿迁市| 霞浦县| 济阳县| 中牟县| 法库县| 吉木萨尔县| 长沙市| 监利县| 视频| 峨边| 景德镇市| 苏尼特右旗| 利川市| 新巴尔虎右旗| 磴口县| 陇南市| 咸丰县|