Caliburn行动没有开火

时间:2014-01-14 22:19:11

标签: caliburn.micro

<ItemsControl DockPanel.Dock="Right"  x:Name="Actions">
    <ItemsControl.ItemTemplate>
        <DataTemplate>
            <Button x:Name="Action"  
                    HorizontalAlignment="Right" 
                    Content="{Binding Label}" 
                    Margin="3" Width="30"></Button>
        </DataTemplate>
    </ItemsControl.ItemTemplate>

    <ItemsControl.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>

        </ItemsPanelTemplate>
    </ItemsControl.ItemsPanel>
</ItemsControl>

以上视图与此viewmodel

绑定
public class DeploymentInputViewModel<T> : PropertyChangedBase
{
   public BindableCollection<InputActionViewModel> Actions {get;set;}
}

我看到了我的按钮。但点击它时没有任何事情发生。

InputActionViewModel的viewModels:

public abstract class InputActionViewModel{
    public InputActionViewModel()
    {

    }
    public virtual Task Action()
    {
        return Task.FromResult<object>(null);
    }
    public string ActionToolTip { get; set; }
    public string Label { get; set; }

    public object Value { get; set; }
}

以及

public class InputCertificateActionViewModel : InputActionViewModel
{
    [Import]
    private IShell _shell;
    [Import]
    private IWindowsDialogs _dialogs;

    private readonly IDeploymentSettingInputViewModel vm;
    public InputCertificateActionViewModel(IDeploymentSettingInputViewModel vm) 
    {
        this.vm = vm;
        Label = "...";
        ActionToolTip = "Pick a Certificate";
    }

    public bool IsManagementCertificate {get;set;}
    public bool IsDeploymentCertificate { get; set; }
    public async override Task Action()
    {
        if(IsManagementCertificate)
        {
            var subs = await _shell.IdentityModel.GetEnabledSubscriptionsAsync();
           foreach(var sub in subs)
           {
               using (ManagementClient client = CloudContext.Clients.CreateManagementClient(sub.GetCredentials()))
               {
                   var cert = _dialogs.SelectItemDialog("Select a certificate", "Pick one", true,
                       (await client.ManagementCertificates.ListAsync()).Select(c =>
                           new SelectItem(c.Thumbprint, Encoding.Default.GetString(c.PublicKey), c, (s) => c.Thumbprint.Contains(s))).ToArray())
                           .Tag as ManagementCertificateListResponse.SubscriptionCertificate;
                   this.vm.Value = cert.Thumbprint;
               }

           }


        }else if(IsDeploymentCertificate)
        {

        }



    }
}

我通过在启动时直接插入可观察代码来添加actionViewModels。

haveActions.Actions.Add(DI.BuildUp(new InputCertificateActionViewModel(vm)
{
    IsDeploymentCertificate = certAttribute.IsDeploymentCertificate,
    IsManagementCertificate = certAttribute.IsManagementCertificate,
}));

hasActions是InputCertificateActionViewModel

的一个实例

1 个答案:

答案 0 :(得分:0)

无法将此全部纳入评论:

我目前无法查看Caliburn.Micro,但可能与调用您的方法Action有关。

但我猜想,按惯例Caliburn.Micro我希望找到一个与Action<T>委托相匹配的方法Actions,这样你的public virtual Task Action() }将不会被定位和绑定。

通过定义具有兼容签名的新方法进行快速检查,例如public void MyMethod()并检查其是否正确定位并将起作用。

如果这是问题所在,您可能需要查看Caliburn.Micro documentationIResult and Coroutines部分,看起来它可以帮助您实现所需的行为。