我遇到了与Windows Phone 8的RadDataBoundListBox命令绑定的事件的问题。
我有以下XAML:
<Grid x:Name="LayoutRoot" Background="{StaticResource PivotBackground}" DataContext="{Binding RecomandationViewModel, Source={StaticResource Locator}}">
..........
<telerikPrimitives:RadDataBoundListBox x:Name="DataBoundListBox" ItemsSource="{Binding RecommendedSongs}" DisplayMemberPath="Name" EmptyContent=" " DataVirtualizationMode="OnDemandAutomatic">
<i:Interaction.Triggers>
<i:EventTrigger EventName="DataRequested">
<command:EventToCommand Command="{Binding DataRequestedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<telerikPrimitives:RadDataBoundListBox.ItemLoadingTemplate>
<DataTemplate>
<bitrimitives:BitBusyIndicator IsRunning="True" AnimationStyle="AnimationStyle9" Foreground="{StaticResource MyColor}" Content=""/>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemLoadingTemplate>
</telerikPrimitives:RadDataBoundListBox>
</Grid>
视图模型代码:
private RelayCommand _dataRequestedCommand;
public RelayCommand DataRequestedCommand
{
get
{
if (_dataRequestedCommand == null)
{
_dataRequestedCommand = new RelayCommand(DataRequested, () => true);
}
return _dataRequestedCommand;
}
}
private void DataRequested()
{
int i = 4;
}
DataRequested方法永远不会被触发,但如果我订阅RadDataBoundListBox的DataRequested事件,则会触发该方法。你能帮我解决这个问题吗?
答案 0 :(得分:0)
看看这个link。也许它可以帮助你。
OnDemandAutomatic虚拟化模式是一种模式,在最终用户接近可滚动列表末尾时自动请求数据项。通过使用RadDataBoundListBox公开的ItemLoadingContent和ItemLoadingTemplate属性,可以显示指示正在处理数据请求的专用可视容器。定义ItemLoadingTemplate的可能方法如下所示:
<telerikPrimitives:RadDataBoundListBox.ItemLoadingTemplate>
<DataTemplate>
<Grid MinHeight="14">
<Grid.Triggers>
<EventTrigger>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="ellipseTranslate" RepeatBehavior="Forever">
<DoubleAnimation.EasingFunction>
<SineEase EasingMode="EaseInOut" />
</DoubleAnimation.EasingFunction>
</DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
<Ellipse VerticalAlignment="Center" HorizontalAlignment="Left" Width="6" Height="6" Grid.Column="1" Fill="{StaticResource PhoneAccentBrush}">
<Ellipse.RenderTransform>
<TranslateTransform x:Name="ellipseTranslate" X="0" />
</Ellipse.RenderTransform>
</Ellipse>
</Grid>
</DataTemplate>
</telerikPrimitives:RadDataBoundListBox.ItemLoadingTemplate>
要使用OnDemandAutomatic虚拟化模式,只需将RadDataBoundListBox控件的DataVirtualizationMode属性设置为DataVirtualizationMode.OnDemandAutomatic。您还需要处理DataRequested事件,该事件将在需要加载更多数据时触发:
public MainPage()
{
InitializeComponent();
this.radDataBoundListBox.DataVirtualizationMode = DataVirtualizationMode.OnDemandAutomatic;
this.radDataBoundListBox.DataRequested += this.OnDataRequested;
}
private void OnDataRequested(object sender, EventArgs args)
{
//TODO: download data items
}