• Win10 UWP xaml 延迟加载元素


    xaml新增x:DeferLoadStrategy里面只有Lazy,查询了百度看到MSP_甄心cherish大神说的
    xaml使用x:DeferLoadStrategy="Lazy"延迟加载元素
    我写了代码

        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.RowDefinitions>
                <RowDefinition/>
                <RowDefinition/>
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <Image x:Name="ximg1" Source="/assets/1.jpg" Grid.Row="0" Margin="10,10,10,10"/>
            <Image x:Name="ximg2" Source="/assets/2.jpg" Grid.Row="1" Margin="10,10,10,10" x:DeferLoadStrategy="Lazy"/>
            <Button Content="显示" Grid.Row="2" Margin="10,10,10,10" HorizontalAlignment="Right" Click="Button_Click"/>
        </Grid>

    ximg1显示,ximg2不显示
    点击按钮就显示ximg2
    1.jpg和2.jpg都是随意的图片

    这样和原先的Visibility="Collapsed"没有显示可是有加载好在不浪费资源,可以到用到才加载。

    点击button

            private void Button_Click(object sender , RoutedEventArgs e)
            {
                FindName(nameof(ximg2));
            }

    如果写FindName("ximg2");容易写错

    程序启动
    程序启动
    点击显示
    点击显示

    这样做对于要加载大量的图片,而不是在用户需要显示,可以先延迟,到了需要再加载,这样加快了速度。

    参考:http://blog.csdn.net/zmq570235977/article/details/47404437

    <script type="text/javascript"> $(function () { $('pre.prettyprint code').each(function () { var lines = $(this).text().split(' ').length; var $numbering = $('<ul/>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('<li/>').text(i)); }; $numbering.fadeIn(1700); }); }); </script>
  • 相关阅读:
    潜水员
    混合背包
    多重背包问题
    归并排序——最省时的排序
    HDU 1556 Color the ball
    2016 ACM/ICPC Asia Regional Dalian Online Football Games
    poj 2352 Stars
    poj 2299 Ultra-QuickSort
    关于原码反码补码以及位元算
    2016 湖南省省赛 Problem A: 2016
  • 原文地址:https://www.cnblogs.com/lindexi/p/6949731.html
Copyright © 2020-2023  润新知