Is there a way to modify the default "No Preference" label of the button when updating the user inputs to read e.g. "I don't want to change anything." without introducing a new Resources.*.resx file?
I tried all templates that allow changing such literals but I found no one that could achieve this. TemplateUsage.NoPreference can be used to change only the value of an optional field, not the button label.
You can do it by overriding the Template value in your FormFlow.
Here is an example based on the Microsoft.Bot.Sample.SimpleSandwichBot:
public static IForm<SandwichOrder> BuildForm()
{
var formBuilder = new FormBuilder<SandwichOrder>()
.Message("Welcome to the simple sandwich order bot!");
var noPreferenceStrings = new string[] { "Nothing" };
// Set the new "no Preference" value
formBuilder.Configuration.Templates.Single(t => t.Usage == TemplateUsage.NoPreference).Patterns = noPreferenceStrings;
// Change this one to help detection of what you typed/selected
formBuilder.Configuration.NoPreference = noPreferenceStrings;
return formBuilder.Build();
}
Demo capture:
Related
I am using the Microsoft Bot Framework and Adaptive cards to have user fill out a form. The form is being created and displayed correctly, but now I am trying to add the ability for users to go back and edit fields of the form (some fields are auto-populated on form creation in certain situations.)
Here is what my card currently looks like (in the Bot Emulator):
Before Quote Name is input
After Quote Name is Entered
I want my card to look like this after I add the edit functionality:
Edit Quote Name
Where the user can click the "Edit" text (which is a textblock in its own column) and have a new TextInput field appear under the "Edit" text as a new inline card. Here is the code I have tried:
new ColumnSet()
{
Columns =
{
new Column()
{
Size = "2",
Items =
{
new TextBlock()
{
Text = "Edit",
Color = TextColor.Accent
}
},
SelectAction = new ShowCardAction()
{
Title = "View",
Card = new AdaptiveCard()
{
Body = new List<CardElement>()
{
new TextBlock()
{
Text = "In the Edit Card",
Weight = TextWeight.Bolder
}
}
}
}
}
},
}
I think the problem is with the ShowCardAction() not working as I expect it to. When I replaced this with an OpenURLAction() a new link was opened when the 'Edit' text was clicked on (so this action worked, but ShowCard didn't).
I referenced this post Adaptive Cards - Nested scheme and the adaptive cards schema explorer here but haven't had any luck.
Has anyone done something like this before and is willing to share how they did it?
Currently SelectActions can only be used with Action.OpenUrl and Action.Submit, as you've observed. I will update the docs to make this more obvious. We do hope to explore adding show card support in the future but need to to get the UX right on every platform.
I'm attempting to find a document on my window that has a rich text box with text in it using TestStack White, and extract that text.
I've tried to use the UIItem Label & TextBox, but White doesn't seem to be able to find the object during my test. The object can be found using the generic UIItem, but I want to be able to access the text it holds.
I'm implementing it like:
public [Unsure] MyRichTextBox
{
get { return Window.Get<[Unsure]>(SearchCriteria.ByClassName("RichTextBox")); }
}
and I'd like to be able to say:
Assert.That(MyRichTextBox.Text.Equals(x));
But it can't find what I'm looking for if I tag it as a Label or a TextBox, and I don't have access to .Text if I declare it a UIItem.
You want to use the type of TextBox. Then you can use BulkText to access the text in the RichEditBox.
First the Window:
TestStack.White.UIItems.WindowItems.Window _mainWindow;
app = TestStack.White.Application.Launch(startInfo);
_mainWindow = app.GetWindow("MyDialog");
Then Find the richEditBox:
public string _richeditdocument_ID = "rtbDocument";
private TextBox _richeditdocument_ = null;
public TextBox RichEditDocument
{
get
{
if (null == _richeditdocument_)
_richeditdocument_ = _mainWindow.Get<TextBox>(SearchCriteria.ByAutomationId(_richeditdocument_ID));
return _richeditdocument_;
}
}
Then use the following to access the text:
string data = RichEditDocument.BulkText;
Here are the code comments for using the Text Method in White:
// Summary:
// Enters the text in the textbox. The text would be cleared first. This is
// not as good performing as the BulkText method. This does raise all keyboard
// events - that means that your string will consist of letters that match the
// letters of your string but in current input language.
public virtual string Text { get; set; }
Here are the comments for using BulkText:
// Summary:
// Sets the text in the textbox. The text would be cleared first. This is a
// better performing than the Text method. This doesn't raise all keyboard events.
// The string will be set exactly as it is in your code.
How do i create a new Button/Canvas with a dynamic name?
Button {buttonname read from text file} = new Button;
I have googled this for a while now but i can't find the solution.
Thank you!
I'm not sure if I understood correctly, but that name in your example is not the button name, it's just the reference name used in code to access the button. The button name would be set like this:
buttonRefName.Name = "ButtonName1";
So you can set the name to whatever you want: dynamically generated names inside a loop, names read from a file, etc...
You can use the same reference name for multiple buttons, just be sure to add it to List or to WPF Window, Panel, etc... before creating the new one:
var buttonList = new List<Button>();
var buttonRef = new Button { Name = "YourButtonName" };
buttonList.Add(buttonRef);
buttonRef = new Button { Name = "YourButtonName2" };
buttonList.Add(buttonRef);
It not possible the way you want to do it. If you are reading from a text file better use a List or better a Dictionary... an example use is as follows:
var buttons = new Dictionary<string, Button>();
buttons["yourName"] = new Button();
// logic goes here
As you can see in that screenshot in "objArgs" there is a property "Text". How can I reach that property?
You need to cast the args to ToolBarItemEventArgs, at which point you can access the ToolBarButton it refers to:
var toolBarArgs = (ToolBarItemEventArgs) objArgs;
switch (toolBarArgs.ToolBarButton.Text)
{
...
}
However, I would suggest not switching on the text. Instead, ideally set up a different event handler for each of your buttons. If you really can't do that, you can use:
var toolBarArgs = (ToolBarItemEventArgs) objArgs;
var button = toolBarArgs.ToolBarButton;
if (button == saveButton)
{
...
}
Or you could switch on the Name rather than the Text - I'd expect the Name to be basically an implementation detail, whereas the Text is user-facing and could well be localized.
I have created a messagebox which returns DialogResult. Now I added checkbox on it and want to know if it is checked or not. So what should I return? The simple way I thought is to create new enum which will have all the values from DialogResult plus a value to indicate checkbox status
public enum MyDlgResult
{
NONE = DialogResult.NONE,
OK = DialogResult.OK ........................,
CHKBOXCHECKED = 8
}
...and returning this enum MyDlgResult.
But is this correct approach? Because I have to add value in this enum every time a new functionality is added to my messagebox.
Better way to do this if any.
Thank You.
Just add Property to that message box, which will be a proxy to Checked property of CheckBox and on OK result form message box check that new Property.
Property to add
public bool Checked
{
get { return yourCheckBox.Checked; }
}
And final code like this
MessBox box = new MessBox();
if(box.Show() == DialogResult.OK)
{
bool isChecked = box.Checked;
}
You don't have to override the return of a dialog to enable the client code to get the state of a UI control. The dialog information is retained after it is closed and you can get values from it. For example, assume that there is a Form class named SomeDlg with a property called PublicDlgProperty. PublicDlgProperty can be set on OK, or any other UI change and then queried after the dialog is closed, like this:
var someDlg = new SomeDlg();
someDlg.ShowDialog();
var someLocalVariable = someDlg.PublicDlgProperty;
This is a very simple example. You'll need to test the DialogResult to see if you want to query the value or not.
I agree with both other people who answered you that you should have a property, delegating the IsChecked or something, but if you must do it using only the return enum result...
Make the enum Flagged:
[Flags]
public enum MyDlgResult
{
NONE = ...
OK = ...
CHK...
}
Then, you can return:
return MyDlgResult.NONE | MyDlgResult.CHK;
Or
return MyDlgResult.OK | MyDlgResult.CHK;
Or just
return MyDlgResult.OK;
And so on...
Then, you can check:
if (res.HasFlag(MyDlgResult.OK))
{
}
if (res.HasFlag(MyDlgResult.CHK))
{
}