How to Display Entry Control with PlaceHolder Text in MAUI.
I need to write a EntryHandler which would look like the below Image
(Last Name* is the placeholder text)
I have written a entry handler with out the border which is looking like below, the problem with this is as the user starts typing the placeholder text hides
public class BorderlessEntry : Entry
{
}
public App(AppShell page)
{
InitializeComponent();
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(nameof(BorderlessEntry), (handler, view) =>
{
if (view is BorderlessEntry)
{
#if __ANDROID__
handler.PlatformView.SetBackgroundColor(Microsoft.Maui.Graphics.Colors.Transparent.ToAndroid());
handler.PlatformView.Hint = view.Placeholder;
#elif __IOS__
handler.PlatformView.BackgroundColor = Microsoft.Maui.Graphics.Colors.Transparent;
handler.PlatformView.Layer.BackgroundColor = Microsoft.Maui.Graphics.Colors.Transparent;
handler.PlatformView.BorderStyle = UIKit.UITextBorderStyle.None;
#endif
}
});
}
I have been able to achieve the same in Xamarin Forms using MaterialEntryRenderer but the same is not supported in .net Maui
Any help is appreciated!
Related
I've seen various answers to this question for older versions but not sure how to translate to MAUI. The question being, is there a way that you can minimize the soft keyboard on a device from the Text Completed event of an Entry control?
I finally figured out how to do this. This solution is for Android only right now. It doesn't use a custom handler since I could not get the window token from PlatformView. Instead the code looks like this:
#if ANDROID
var imm = (Android.Views.InputMethods.InputMethodManager)MauiApplication.Current.GetSystemService(Android.Content.Context.InputMethodService);
if (imm != null)
{
//this stuff came from here: https://www.syncfusion.com/kb/12559/how-to-hide-the-keyboard-when-scrolling-in-xamarin-forms-listview-sflistview
var activity = Microsoft.Maui.ApplicationModel.Platform.CurrentActivity;
Android.OS.IBinder wToken = activity.CurrentFocus?.WindowToken;
imm.HideSoftInputFromWindow(wToken, 0);
}
#endif
So credit to the syncfusion folks that published their version, and this code above is modified from that to work in MAUI.
The code belongs in a custom handler. Based on Customize a control with a mapper.
In that Maui handler, handler.PlatformView is the Android control. Xamarin.Android properties/methods would be on that.
Something like:
using Microsoft.Maui.Platform;
namespace CustomizeHandlersDemo;
public partial class CustomizeEntryPage : ContentPage
{
public CustomizeEntryPage()
{
InitializeComponent();
ModifyEntry();
}
void ModifyEntry()
{
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(
"MyCustomization", (handler, view) =>
{
#if ANDROID
handler.PlatformView....
#elif IOS
#elif WINDOWS
#endif
});
}
}
NOTE: That example modifies ALL Entries.
If you want to modify only SOME Entries, you instead define a subclass (e.g. public class MyEntry : Entry {}), and do this:
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(
"MyEntryCustomizationOrWhatever", (handler, view) =>
{
if (view is MyEntry)
{
#if ANDROID
handler.PlatformView....
#elif IOS
#elif WINDOWS
#endif
}
});
For your specific situation, the line you were having trouble adapting to Maui contains btnSignIn.WindowToken.
Replace that with handler.PlatformView.WindowToken.
Is it possible to add aria labels to a Kentico form. I am adding the forms to my pages using the online form widget and I would like to add aria labels to each section to help make my site more ADA compliant.
I don't see the option by default in Kentico. It's a good request though. What you would need to do is to create your own form control that has the property.
https://docs.kentico.com/k10/custom-development/developing-form-controls
What you would look to do is clone the Textbox, add a property called "AriaLabel" to the form control's properties, then add this to the new code file for the textbox
In Properties region:
public string AriaLabel
{
get
{
return ValidationHelper.GetString(GetValue("AriaLabel"), "");
}
set
{
if (txtValue.Attributes["AriaLabel"] != null)
{
txtValue.Attributes["AriaLabel"] = ValidationHelper.GetString(GetValue("AriaLabel"), "");
}
else
{
txtValue.Attributes.Add("AriaLabel", ValidationHelper.GetString(GetValue("AriaLabel"), ""));
}
}
}
In Page_Load at bottom:
if (txtValue.Attributes["AriaLabel"] != null)
{
txtValue.Attributes["AriaLabel"] = AriaLabel;
}
else
{
txtValue.Attributes.Add("AriaLabel", AriaLabel);
}
If you will utilize label attribute for a field it will generate label tag for it in the HTML layout which will be accessibility compliant. Will that solve your purpose or are you looking specifically for aria-label tag only?
I just upgraded from Umbraco 4.7.1 to 6.1.6
I have a TinyMCE control in my custom section. It stopped working after the upgrade.Here is part of my code for the page in the custom section:
public partial class MyCustomPage : UmbracoEnsuredPage
{
private TinyMCE txtLongDesc;
protected UmbracoPanel UmbPanel { get { return Web.FindControlRecursive(Master, "umpContent") as UmbracoPanel; } }
protected override void Page_Init(object sender, EventArgs e)
{
base.Page_Init(sender, e);
PutTinyMce(ref txtLongDesc, "txtLongDesc", phLongDesc, UmbPanel);
}
public static void PutTinyMce(ref TinyMCE control, string controlId, PlaceHolder placeHolder, UmbracoPanel panel)
{
DataTypeDefinition d = DataTypeDefinition.GetDataTypeDefinition(2710); // My custom TinyMCE DataType
control = (umbraco.editorControls.tinyMCE3.TinyMCE)d.DataType.DataEditor;
control.ID = controlId;
placeHolder.Controls.Add(control);
panel.Menu.NewElement("div", "umbTinymceMenu_" + control.ClientID, "tinymceMenuBar", 0); // Add TinyMCE controls to menu bar
}
}
When the page is rendered, the textarea is hidden, but the TinyMCE is not shown.This is the JavaScript error I got:
TypeError: document.getElementById(...) is null #
.../umbraco/plugins/tinymce3/tinymce3tinymceCompress.aspx?rnd=00000000-0000-0000-0000-000000000000&module=gzipmodule&themes=umbraco&plugins=contextmenu,umbracoimg,paste,inlinepopups,table,umbracocss,advlink,umbracoembed,spellchecker,noneditable,umbracomacro,umbracopaste,umbracolink,umbracocontextmenu&languages=en:19803
This is the line causing the error (line 19803)
document.getElementById(ed.getParam("umbraco_toolbar_id", "*")).appendChild(c);
Has anyone experienced this problem? Any idea how to fix it?
After fiddling with it, I managed to fix it, although I don't really understand why.
Apparently in Umbraco 6.1.6 you have to add umbraco_toolbar_id manually, so I added these 2 lines
control.ClientIDMode = ClientIDMode.Static;
control.config.Add("umbraco_toolbar_id", "umbTinymceMenu_" + control.ClientID);
to this function, which becomes
public static void PutTinyMce(ref TinyMCE control, string controlId, PlaceHolder placeHolder, UmbracoPanel panel)
{
DataTypeDefinition d = DataTypeDefinition.GetDataTypeDefinition(Static.DTD_ID_SMALL_RTE); // Custom TinyMCE DataType
control = (umbraco.editorControls.tinyMCE3.TinyMCE)d.DataType.DataEditor;
control.ID = controlId;
control.ClientIDMode = ClientIDMode.Static;
control.config.Add("umbraco_toolbar_id", "umbTinymceMenu_" + control.ClientID);
placeHolder.Controls.Add(control);
panel.Menu.NewElement("div", "umbTinymceMenu_" + control.ClientID, "tinymceMenuBar", 0); // Add TinyMCE controls to menu bar
}
That fixed it. My TinyMCE appears again :)
i'm doing i18n to my application i did something that is shown in showcase example i'm using the listbox to show different locales, the problem is when i'm swapping from one locale to another locale,locale is changing but the list box is not showing the locale in which i am, it is showing first element of the list every time as it is reloading
here is code:
#Override
public void changeSwap() {
final String queryParam = LocaleInfo.getLocaleQueryParam();
String locale=getView().getLocale().getValue(getView().getLocale().getSelectedIndex());
Log.info("revealed locale is"+locale);
if (queryParam != null) {
UrlBuilder builder = Location.createUrlBuilder().setParameter(
queryParam, locale);
Window.Location.replace(builder.buildString());
} else {
// If we are using only cookies, just reload
Window.Location.reload();
}
}
i didn't find any method in listbox api to do it
thanks
You're using a part of the code from the Showcase (ShowcaseShell.initializeLocaleBox()), but the part that is responsible for selecting the correct value in the ListBox is this:
String currentLocale = LocaleInfo.getCurrentLocale().getLocaleName();
if (currentLocale.equals("default")) {
currentLocale = "en";
}
String[] localeNames = LocaleInfo.getAvailableLocaleNames();
for (String localeName : localeNames) {
if (!localeName.equals("default")) {
String nativeName = LocaleInfo.getLocaleNativeDisplayName(localeName);
localeBox.addItem(nativeName, localeName);
if (localeName.equals(currentLocale)) {
localeBox.setSelectedIndex(localeBox.getItemCount() - 1);
}
}
}
Make sure to add it to your code before adding the ChangeHandler to the localeBox.
Here's the full setup in the Showcase 2.4.0 example:
Showcase.gwt.xml 21-28 performs the locale setup for the module (especially it defines the available locales as "en", "ar", "fr", "zh")
ShowcaseShell.ui.xml 204-206 creates the ListBox widget.
ShowcaseShell.java 113-114, 190, 322-364 fill the available locales into the ListBox, and adds a ChangeHandler.
I would recommend to create a simple new GWT project (at first without gwtp or anything special) and just add these bits of code. Then you can try to migrate the setup to your full project.
I want to implement menu in GWT as shown on this website:
http://www.openkm.com/en/
I have created the menu system and I am able to display alerts from menu using following code:
Command cmd = new Command() {
public void execute() {
Window.alert("Menu item have been selected");
}
}
I want to get rid of window.alert() and display my application pages from menu.
Create and load the appropriate page. For example if you use UiBinder then:
MyPage selectedPage = new MyPage(); // creating of your panel
RootPanel.get().clear(); // cleaning of rhe RootPanel
RootPanel.get().add(selectedPage); // adding the panel to the RootPanel
First create an array list of views
public List<UIObject> viewsList = new ArrayList<UIObject>();
Add a view to that list
viewsList.add(addMovieView);
Send the view you want to select to the helper method
public void changeView(UIObject selectedView) {
for(UIObject view : viewsList) {
if(selectedView.equals(view)) {
view.setVisible(true);
} else {
view.setVisible(false);
}
}
}
Are you trying to make the entire page GWT, or just the menu? If it's just the menu, you will need to embed a GWT element into your overall HTML, then call something like
Window.open(linkURL, "_self", "");
from the appropriate menu items, which will navigate to another page.