BusyIndicator.Message 绑定到字符串集合
我正在尝试将 SL BusyIndicator 绑定到繁忙消息的集合。当集合有项目时,指示器将显示消息。当消息集合为空时,指示器将隐藏。
首先,指示器没有显示我的消息,我看到的只是一个空白的指示器框,带有不确定的进度条:
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码非常接近目标,要使其正常工作,您所需要做的就是将行替换
为
我在 Silverlight 3 和 5 中测试过的行,因此我认为它也可以在 Silverlight 4 中工作。
我不确定您的
AllocationLoadingMessages
属性的set { }
代码的用途;您不必在每次更改集合时都替换它。当我让它工作时,我在视图模型中所做的就是这样:很抱歉我迟到了(直到现在才遇到这个问题),但我希望它至少可以帮助其他正在寻找的人对此的答案。
Your code is very near the target, all you need to do to get this to work is to replace the line
with
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 theAllocationLoadingMessages
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: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.