Frage

<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>

The above view binds with this viewmodel

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

I see my buttons. But when clicking it nothing happen.

The viewModels for InputActionViewModel:

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; }
}

and also

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)
        {

        }



    }
}

I am adding actionViewModels by inserting directly into the observable code at startup.

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

haveActions is an instance of InputCertificateActionViewModel

War es hilfreich?

Lösung

Couldn't fit this all in a comment:

I can't have a peek at the Caliburn.Micro at the moment, but it might be something related to calling your method Action.

At a guess though, I'd say that by convention Caliburn.Micro expects to find a method that matches the Action<T> delegate to use for it's Actions, so your public virtual Task Action() won't be located and bound.

Have a quick check by defining a new method with a compatible signature, e.g public void MyMethod() and checking to see if it's located correctly and will function.

If that is the problem, you'll probably want to have a look at the IResult and Coroutines part of the Caliburn.Micro documentation, which looks like it will help you implement your desired behaviour.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top