私の問題を説明させてください。長い質問で失礼します。ここに行きます。
ビューがあります(BusyProviderView)
<Grid>
<xctk:BusyIndicator x:Name="aaa" IsBusy="{Binding IsRunning}" >
<xctk:BusyIndicator.BusyContentTemplate>
<DataTemplate>
<Grid cal:Bind.Model="{Binding}">
<TextBlock Name="Message"/>
</Grid>
</DataTemplate>
</xctk:BusyIndicator.BusyContentTemplate>
</xctk:BusyIndicator>
</Grid>
ビューモデルがあります:
public class BusyProviderViewModel : PropertyChangedBase, IBusyProvider
{
//two properties with INPC, Message and IsRunning
}
再び私はシェルビューを持っています
<Window x:Class="MvvmTest.ShellView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="ShellView" Height="300" Width="300">
<Grid>
<Button Height="25" x:Name="Run">Run</Button>
<ContentControl x:Name="BusyProvider"/>
</Grid>
ビューモデルがあります
public class ShellViewModel : PropertyChangedBase, IShellViewModel
{
private IBusyProvider busyProvider;
public ShellViewModel(IBusyProvider busy)
{
this.BusyProvider = busy;
}
public IEnumerable<IResult> Run()
{
yield return new DummyOperation(this.BusyProvider);
}
public IBusyProvider BusyProvider
{
get
{
return this.busyProvider;
}
set
{
if (Equals(value, this.busyProvider))
{
return;
}
this.busyProvider = value;
this.NotifyOfPropertyChange(() => this.BusyProvider);
}
}
}
DummyOperationルックス
public class DummyOperation : IResult
{
public IBusyProvider Provider { get; set; }
public DummyOperation(IBusyProvider provider)
{
Provider = provider;
}
public void Execute(ActionExecutionContext context)
{
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += (a, b) =>
{
Provider.IsRunning = true;
Provider.Message = "Working";
Thread.Sleep(TimeSpan.FromSeconds(5));
Provider.Message = "Stopping";
Thread.Sleep(TimeSpan.FromSeconds(5));
Provider.IsRunning = false;
};
worker.RunWorkerCompleted += (a, b) =>
{ Completed(this, new ResultCompletionEventArgs()); };
worker.RunWorkerAsync();
}
public event EventHandler<ResultCompletionEventArgs> Completed;
}
最後に私はBootStrapperを持っています
public class AppBootstrapper : Bootstrapper<IShellViewModel>
{
private Container container;
protected override void Configure()
{
this.container = new Container();
this.container.Register<IWindowManager,WindowManager>();
this.container.Register<IShellViewModel,ShellViewModel>();
this.container.Register<IBusyProvider, BusyProviderViewModel>();
}
protected override object GetInstance(Type serviceType, string key)
{
return this.container.GetInstance(serviceType);
}
protected override IEnumerable<object> GetAllInstances(Type serviceType)
{
return this.container.GetAllInstances(serviceType);
}
protected override void BuildUp(object instance)
{
this.container.Verify();
}
}
すべてを設定したように見えますが、実行しようとすると例外がスローされます。
私は問題が原因であると確信しています
<DataTemplate>
<Grid cal:Bind.Model="{Binding}">
<TextBlock Name="Message"/>
</Grid>
</DataTemplate>
cal:Bind.Model = "{Binding}
上記のステートメントを削除すると、プログラムはクラッシュせずに実行されますが、バインディングはありません。
画像を見ると、
protected override object GetInstance(Type serviceType, string key)
{
return this.container.GetInstance(serviceType);
}
serviceTypeはNULLとして渡され、キーは「Please Wait ....」です。これはどこから来たのですか?