2

私の問題を説明させてください。長い質問で失礼します。ここに行きます。

ビューがあります(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 ....」です。これはどこから来たのですか?

4

2 に答える 2

5

デフォルトでは、ExtendedToolkitはのBusyIndicator文字列を使用して"Please Wait...."いるようですBusyContent。したがって、の中にDataTemplateDataContext上記の文字列があり、これがCaliburnで混乱と例外を引き起こします。

BusyContentこれを修正するには、BusyIndicatorを現在に設定する必要がありDataContext、それが機能します。

<xctk:BusyIndicator x:Name="aaa" IsBusy="{Binding IsRunning}" 
                                 BusyContent="{Binding}" >
    <xctk:BusyIndicator.BusyContentTemplate>
        <DataTemplate>
            <Grid cal:Bind.Model="{Binding}">
                <TextBlock Name="Message"/>
            </Grid>
        </DataTemplate>
    </xctk:BusyIndicator.BusyContentTemplate>
</xctk:BusyIndicator>
于 2012-08-18T16:22:56.023 に答える
0

Olegは正しいと思いますが、Caliburnを使用してDataTemplateで規則を使用することはできません(CaliburnMicroを使用できます)。ドキュメントから-その他の知っておくべきこと

その他の注意事項すべてのプラットフォームで、DataTemplateのコンテンツに規則を適用することはできません。これは、Xamlテンプレートシステムの現在の制限です。私はマイクロソフトにこれを修正するように依頼しましたが、彼らが応答するとは思えません。そのため、データテンプレートにバインディングとアクションの規則を適用するには、DataTemplate内のルート要素にBind.Model="{Binding}"添付プロパティを追加する必要があります。これにより、Caliburn.MicroがDataTemplateからUIがインスタンス化されるたびにその規則を適用するために必要なフックが提供されます。

于 2012-08-18T15:04:35.530 に答える