如何在TabItem标头中显示忙碌指示器 [英] How to Show busy indicator in TabItem header

查看:89
本文介绍了如何在TabItem标头中显示忙碌指示器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中使用了选项卡控件,并且在加载tabcontent时,我需要在选项卡项目标题中显示忙碌指示符.如何在MVVM中实现这一目标?

In my application have used tab control and i need to show busy indicator in tab item header when tabcontent loading .  how to achieve this in MVVM  ?

推荐答案

有关如何将TabControl绑定到视图模型的源集合的示例,请参考以下线程: http://stackoverflow.com/questions/5650812/how-do-i-bind-a-tabcontrol-to-a-collection-of-viewmodels

Please refer to the following thread for an example of how to bind a TabControl to a source collection of a view model to begin with: http://stackoverflow.com/questions/5650812/how-do-i-bind-a-tabcontrol-to-a-collection-of-viewmodels

然后可以使用BooleanToVisibilityConverter将忙碌指示器添加到ItemTemplate并将其Visibility属性绑定到数据对象的属性:

You could then add your busy indicator to the ItemTemplate and bind its Visibility property to a property of the data object using a BooleanToVisibilityConverter:

      <TabControl x:Name="tab" ItemsSource="{Binding Tabs}">
            <TabControl.Resources>
                <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
            </TabControl.Resources>
            <TabControl.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <ProgressBar IsIndeterminate="True" Width="20"
                                     Visibility="{Binding IsLoading, Converter={StaticResource BooleanToVisibilityConverter}}" />
                        <TextBlock Text="{Binding Header}" />
                    </StackPanel>
                </DataTemplate>
            </TabControl.ItemTemplate>
            <TabControl.ContentTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Content}" />
                </DataTemplate>
            </TabControl.ContentTemplate>
        </TabControl>


然后,视图模型负责根据您的加载逻辑设置数据对象类的IsLoading属性(在上面的线程中名为"TabItem").请注意,视图模型类必须实现INotifyPropertyChanged接口 并在IsLoading属性设置为true/false时引发更改通知: https://msdn.microsoft.com/zh-CN/library/system.componentmodel.inotifypropertychanged%28v=vs.110%29.aspx

The view model is then responsible for setting the IsLoading property of the data object class (named "TabItem" in the thread above) according to your loading logic. Note that the view model class must implement the INotifyPropertyChanged interface and raise change notifications when the IsLoading property is set to true/false: https://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged%28v=vs.110%29.aspx


希望有帮助.


Hope that helps.

请记住,通过将有用的帖子标记为答案来关闭话题,然后在遇到新问题时开始新话题.请不要在同一线程中问几个问题.

Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.


这篇关于如何在TabItem标头中显示忙碌指示器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆