开发者

WPF - a preload image or template before TabItem load

开发者 https://www.devze.com 2023-03-26 09:49 出处:网络
I have a listbox in TabContorol that bind to a database, it takes a little while to load. 开发者_开发百科i want show a preload image or template before TabItem and listbox loaded and after load became

I have a listbox in TabContorol that bind to a database, it takes a little while to load. 开发者_开发百科i want show a preload image or template before TabItem and listbox loaded and after load became complete the preload image be diasapear. help me plz


I would use a Trigger in the ListBox.Style, and if the ItemSource is null I would rewrite the ListBox.Template using a Loading Image instead of the regular ListBox template.

Here's an example:

<Style TargetType="{x:Type ListBox}">
    <Style.Triggers>
        <DataTrigger Property="{Binding MyList}" Value="{x:Null}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <Image Source="loadingImage.gif" />
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </DataTrigger>
    </Style.Triggers>
</Style>

I didn't run this through a compiler so I might have some syntax errors, but it should point you in the right direction.

0

精彩评论

暂无评论...
验证码 换一张
取 消