Skip to content

Latest commit

 

History

History
95 lines (86 loc) · 3.05 KB

xaml-designer-suggested-actions-extensibility-features.md

File metadata and controls

95 lines (86 loc) · 3.05 KB

Quick Actions Features

In 16.7 there are 5 types of actions that could be added:

PropertyAction

//Simple Property Editor will be shown
PropertyAction propertyAction = new PropertyAction("Content");

extensibility-migration-architecture

//Property Editor with '...' button will be shown
PropertyAction propertyActionWithDialogButton = new PropertyAction("Content");
propertyActionWithDialogButton.DialogOpenAction = () =>
            {
                MessageBox.Show("Dialog Text");
            };

extensibility-migration-architecture

LinkAction - hyperlink label that invokes custom action

LinkAction linkAction = new LinkAction("Help", () =>
{
    Process.Start("http://microsoft.com");
};

extensibility-migration-architecture

CommandAction - hyperlink label that invokes existing command

ShowDialogCommand showDialogCommand = new ShowDialogCommand("Dialog Text");
CommandAction commandAction = new CommandAction("Call 'Show Dialog' Command", showDialogCommand, "CommandParameterObject"))

extensibility-migration-architecture

SelectableAction - hyperlink label that invokes custom action with parameter from ComboBox

SelectableAction selectableAction = new SelectableAction("Set Content to:");
selectableAction.Items = new Dictionary<string, object>()
    {
        { "Content 1", "Test Content 1" },
        { "Content 2", "Test Content 2" }
    };
selectableAction.Action = (obj) =>
{
    this.ModelItem.Content.SetValue(obj);
};

extensibility-migration-architecture

CustomAction - action with custom template

public class MyCustomAction : CustomAction
{
    private SuggestedActionsResources res = new SuggestedActionsResources();
    
    public string MyCustomActionText { get; }
    public ICommand ResetCommand { get; }
    
    public MyCustomAction()
    {
        this.Template = res["MyCustomActionTemplate"] as ControlTemplate;
        this.MyCustomActionText = "Change Content options:";
        this.ResetCommand = new ResetCommandImpl();
    }

    private class ResetCommandImpl : ICommand
    {
        public event EventHandler CanExecuteChanged;
        public bool CanExecute(object parameter)
        {
            return true;
        }
        public void Execute(object parameter)
        {
            if (parameter is ModelItem modelItem)
            {
                modelItem.Content.SetValue("Content");
            }
        }
    }
}

XAML from SuggestedActionsResources ResourceDictionary:

<ControlTemplate x:Key="MyCustomActionTemplate">
    <StackPanel Orientation="Vertical">
        <TextBlock Text="{Binding MyCustomActionText}"/>
        <Button Width="60" Height="20" Margin="2" HorizontalAlignment="Center"
                Content="Reset" 
                Command="{Binding ResetCommand}" CommandParameter="{Binding ModelItem}"/>
    </StackPanel>
</ControlTemplate>