Visual Studio 2015でMVVM Light WPFアプリケーションを構築していますが、これにはWindowsFormsHost
と、SQL Server Reporting ServicesローカルレポートのReportViewer
を含むユーザーコントロールがあります。 ReportView.xaml
のボタンはコマンドを呼び出し、次にコマンドをMasterListView.xaml
のコードビハインドに送信してレポートを生成します。ここでビジー状態インジケーターが表示されない
public ICommand RunReportRelayCommand =>
new RelayCommand(async()=> { await RunReport(); });
private async Task RunReport()
{
try
{
IsBusy = true;
await Task.Run(() =>
{
Messenger.Default.Send(true, "RunMasterListReport");
});
}
finally
{
IsBusy = false;
}
}
ReportViewModel.cs
でIsBusy
プロパティの定義です:ここで
ReportViewModel.cs
のボタンによって呼び出されるコマンドです
private bool _isBusy;
public bool IsBusy
{
get { return _isBusy; }
set
{
if (value == _isBusy) return;
_isBusy = value;
RaisePropertyChanged();
}
}
上記を呼び出すボタンが含まれている同じビュー、ReportView.xaml
、コマンドには、次の拡張WPFツールキットビジーインジケータが含まれます。
<UserControl>
<UserControl.Resources>
<DataTemplate x:Key="MasterListViewTemplate">
<view:MasterListView />
</DataTemplate>
</UserControl.Resources>
<xctk:BusyIndicator IsBusy="{Binding IsBusy}">
<StackPanel>
<!-- Other XAML here -->
<ContentControl ContentTemplate="{StaticResource MasterListViewTemplate}" />
</StackPanel>
</xctk:BusyIndicator>
</UserControl>
次にMasterListView.cs
にコードビハインド、我々はこれを持っている:レポートが5秒ほど後に表示さんが
public partial class MasterListView : UserControl
{
public MasterListView()
{
InitializeComponent();
Messenger.Default.Register<bool>(this, "RunMasterListReport", RunMasterListReport);
}
public async void RunMasterListReport(bool val)
{
await Task.Run(() =>
{
var dataSet = new DrugComplianceDataSet();
dataSet.BeginInit();
ReportViewer.ProcessingMode = ProcessingMode.Local;
ReportViewer.LocalReport.ShowDetailedSubreportMessages = true;
ReportViewer.LocalReport.DataSources.Clear();
var dataSource = new ReportDataSource
{
Name = "MasterListRandomDataSet",
Value = dataSet.MasterListRandom
};
ReportViewer.LocalReport.DataSources.Add(dataSource);
ReportViewer.LocalReport.ReportEmbeddedResource = "MasterListRandom.rdlc";
dataSet.EndInit();
var adapter = new MasterListRandomTableAdapter { ClearBeforeFill = true }
.Fill(dataSet.MasterListRandom);
Dispatcher.Invoke((MethodInvoker)(() => { ReportViewer.RefreshReport(); }));
});
}
}
しかし、ビジーインジケータは、トリガされません。私は間違って何をしていますか?ありがとう。
"インスタント"というメッセージを送信する動作を待っているだけなので、メッセージ受信がトリガするイベントを待つことはありません。私は、非同期RunReportメソッドでデータを取得することをお勧めし、それらの行に沿ったペイロードまたは何かとしてデータを含むメッセージを送信します。データを受信すると、データソースをロードします。それからあなたは期待どおりに待っているべきです。 –
ありがとう、@マークW。あなたは答えのあなたのコメントを精巧に考えていますか? :) – Alex