BusyIndi​​cator.Message 绑定到字符串集合

发布于 2024-08-17 02:47:45 字数 1513 浏览 6 评论 0原文

我正在尝试将 SL BusyIndi​​cator 绑定到繁忙消息的集合。当集合有项目时,指示器将显示消息。当消息集合为空时,指示器将隐藏。

首先,指示器没有显示我的消息,我看到的只是一个空白的指示器框,带有不确定的进度条:

<UserControl.Resources>

...
<anotherAssembly:CollectionToBoolConverter x:Key="CollectionToBoolConverter" />

<DataTemplate x:Key="LoadingMessageDataTemplate">
    <ItemsControl x:Name="itemsControl" ItemsSource="{Binding AllocationLoadingMessages}" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</DataTemplate>

...

</UserControl.Resources>

...

<controlToolkit:BusyIndicator 
    IsBusy="{Binding AllocationLoadingMessages, Converter={StaticResource CollectionToBoolConverter}}"
    BusyContent="{Binding AllocationLoadingMessages}"
    BusyContentTemplate="{StaticResource LoadingMessageDataTemplate}"/>
///content
</controlToolkit:BusyIndicator>

...

ViewModel:

    private ObservableCollection<string> _allocationLoadingMessages = new ObservableCollection<string>();
    public ObservableCollection<string> AllocationLoadingMessages
    {
        get { return _allocationLoadingMessages; }
        set
        {
            SetValue(ref _allocationLoadingMessages, value, "AllocationLoadingMessages");
        }
    }

那么如何在指示器中获取简单的消息列表?

谢谢,
标记

I'm trying to binding a SL BusyIndicator to a collection of busy messages. When the collection has items, the indicator will display the messages. When the collection of messages is empty the indicator will hide.

First off the indicator is not displaying my messages, all I see is a blank indicator box, with an indeterminate progress bar:

<UserControl.Resources>

...
<anotherAssembly:CollectionToBoolConverter x:Key="CollectionToBoolConverter" />

<DataTemplate x:Key="LoadingMessageDataTemplate">
    <ItemsControl x:Name="itemsControl" ItemsSource="{Binding AllocationLoadingMessages}" >
        <ItemsControl.ItemTemplate>
            <DataTemplate>
                <TextBlock Text="{Binding}" />
            </DataTemplate>
        </ItemsControl.ItemTemplate>
    </ItemsControl>
</DataTemplate>

...

</UserControl.Resources>

...

<controlToolkit:BusyIndicator 
    IsBusy="{Binding AllocationLoadingMessages, Converter={StaticResource CollectionToBoolConverter}}"
    BusyContent="{Binding AllocationLoadingMessages}"
    BusyContentTemplate="{StaticResource LoadingMessageDataTemplate}"/>
///content
</controlToolkit:BusyIndicator>

...

ViewModel:

    private ObservableCollection<string> _allocationLoadingMessages = new ObservableCollection<string>();
    public ObservableCollection<string> AllocationLoadingMessages
    {
        get { return _allocationLoadingMessages; }
        set
        {
            SetValue(ref _allocationLoadingMessages, value, "AllocationLoadingMessages");
        }
    }

So how do I get a simple list of messages in my Indiciator?

Thanks,
Mark

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌上青苔 2024-08-24 02:47:45

您的代码非常接近目标,要使其正常工作,您所需要做的就是将行替换

<ItemsControl x:Name="itemsControl" ItemsSource="{Binding AllocationLoadingMessages}" >

<ItemsControl x:Name="itemsControl" ItemsSource="{Binding}" >

我在 Silverlight 3 和 5 中测试过的行,因此我认为它也可以在 Silverlight 4 中工作。

我不确定您的 AllocationLoadingMessages 属性的 set { } 代码的用途;您不必在每次更改集合时都替换它。当我让它工作时,我在视图模型中所做的就是这样:

    public ObservableCollection<string> AllocationLoadingMessages { get; set; }

    private int _loadingMessageNumber = 0;
    private void Add()
    {
        AllocationLoadingMessages.Add( "Loading message #" + ++_loadingMessageNumber );
        PropertyChanged( this, new PropertyChangedEventArgs( "AllocationLoadingMessages" ) );
    }

    private void RemoveFirst()
    {
        if( AllocationLoadingMessages.Count > 0 )
        {
            AllocationLoadingMessages.RemoveAt( 0 );
            PropertyChanged( this, new PropertyChangedEventArgs( "AllocationLoadingMessages" ) );
        }
    }

很抱歉我迟到了(直到现在才遇到这个问题),但我希望它至少可以帮助其他正在寻找的人对此的答案。

Your code is very near the target, all you need to do to get this to work is to replace the line

<ItemsControl x:Name="itemsControl" ItemsSource="{Binding AllocationLoadingMessages}" >

with

<ItemsControl x:Name="itemsControl" ItemsSource="{Binding}" >

I tested this both in Silverlight 3 and 5, so I figure it'll work in 4 as well.

I'm not sure what your set { } code for the AllocationLoadingMessages property is for; you shouldn't have to replace the collection every time you make a change to it. When I got it to work, all I did in the view model was this:

    public ObservableCollection<string> AllocationLoadingMessages { get; set; }

    private int _loadingMessageNumber = 0;
    private void Add()
    {
        AllocationLoadingMessages.Add( "Loading message #" + ++_loadingMessageNumber );
        PropertyChanged( this, new PropertyChangedEventArgs( "AllocationLoadingMessages" ) );
    }

    private void RemoveFirst()
    {
        if( AllocationLoadingMessages.Count > 0 )
        {
            AllocationLoadingMessages.RemoveAt( 0 );
            PropertyChanged( this, new PropertyChangedEventArgs( "AllocationLoadingMessages" ) );
        }
    }

I'm sorry I'm late (didn't come across this question until now), but I hope it can at least help others who are looking for the answer to this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文