2010-01-08 59 views
0

我試圖將SL BusyIndi​​cator綁定到一個忙碌消息的集合。當收集項目時,指示器將顯示消息。當消息收集爲空時,指示器將隱藏。BusyIndi​​cator.Message綁定到字符串集合

首先指示燈不顯示我的消息,我看到的是一個空白的指標中,有一個不確定的進度條:

<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> 

... 

視圖模型:

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

所以我怎麼我的指標中有一個簡單的消息列表?

謝謝,
馬克

+1

是Visual Studio抱怨在運行時在輸出窗口中存在綁定錯誤? – vidalsasoon 2010-01-08 17:22:19

+0

輸出窗口中沒有綁定錯誤。好的建議和感謝你的迅速反應。仍然抨擊我的頭! – 2010-01-11 08:58:16

回答

0

你的代碼是非常接近目標,所有你需要做的就是這個工作是

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

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

我在Silverlight 3和5中測試了這個,所以我認爲它也能在4中工作。

我不確定屬性的代碼是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")); 
     } 
    } 

對不起,我遲到了(沒碰到過這個問題來了到現在爲止),但我希望它可以在最少幫助其他正在尋找答案的人。