Hi
I have succesfully made a custom ajax toolkit with a few buttoms in the footer toolbar as I wish. Now I also want to avoid crtl-v and right-click paste, but have searched, searched and tried everything with no result ... Maybe someone can lead me on the right track, I hope :)
Here below is my code (used with c# on asp.net web pages) which makes a editor control. The first part works, but the last part with the keydown is not working and maybe completely wrong?
Best regards,
Lars, Denmark
My Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Windows.Forms;
using AjaxControlToolkit.HTMLEditor;
/// <summary>
/// Særlig editor tilrettet behovet hos Boost Company
/// </summary>
namespace AjaxControlToolkit.HTMLEditor.BoostToolbarButton
{
public class Bold : AjaxControlToolkit.HTMLEditor.ToolbarButton.Bold
{
public override string ToolTip
{
get { return "Fed"; }
}
}
public class Italic : AjaxControlToolkit.HTMLEditor.ToolbarButton.Italic
{
public override string ToolTip
{
get { return "Kursiv"; }
}
}
public class Cut : AjaxControlToolkit.HTMLEditor.ToolbarButton.Cut
{
public override string ToolTip
{
get { return "Klip"; }
}
}
public class Copy : AjaxControlToolkit.HTMLEditor.ToolbarButton.Copy
{
public override string ToolTip
{
get { return "Kopier"; }
}
}
public class PasteText : AjaxControlToolkit.HTMLEditor.ToolbarButton.PasteText
{
public override string ToolTip
{
get { return "Indsæt"; }
}
}
public class InsertLink : AjaxControlToolkit.HTMLEditor.ToolbarButton.InsertLink
{
public override string ToolTip
{
get { return "Indsæt/ret link"; }
}
}
}
namespace BoostKontroller
{
public class BoostEditor : Editor
{
protected override void FillTopToolbar()
{
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.BoostToolbarButton.Bold());
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.BoostToolbarButton.Italic());
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.BoostToolbarButton.Cut());
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.BoostToolbarButton.Copy());
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.BoostToolbarButton.PasteText());
TopToolbar.Buttons.Add(new AjaxControlToolkit.HTMLEditor.BoostToolbarButton.InsertLink());
}
protected override void FillBottomToolbar()
{
}
void OnKeyDown(KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.V)
{
Clipboard.SetText(string .Empty); ;
}
}
}
}
You can do that:
$find(sControlId).get_editPanel().get_activePanel()._doc.body.onpaste =
function onPasteFunction()
{
$find(sControlId).get_editPanel().get_activePanel()._paste(false, false);
return false;
}
_paste(false, false); is to paste with plain text if you want the word paste the function is _paste(true, true);
sControlId is the client id of the editor.
Related
I'm displaying an OAtuh2 HTML page in WebView that returns me, after clicking on a validation button that is on this page, a redirect URL that I would like to intercept to use the information from it.
in XML file
<ContentPage.Content>
<WebView x:Name="browser"></WebView>
</ContentPage.Content>
in CS file
browser.Source = "https://myUrl";
My low knowledge in Xamarin doesn't allow me to know how to do it
Thanks for your help
You can do as ToolmakerSteve mentioned using WebNavigatingEventArgs.
And for details you can implement this on each specific platform with custom renderer .
iOS
[assembly: ExportRenderer(typeof(WebView), typeof(MyRenderer))]
namespace FormsApp.iOS
{
class MyRenderer : WkWebViewRenderer
{
protected override void OnElementChanged(VisualElementChangedEventArgs e)
{
base.OnElementChanged(e);
this.NavigationDelegate = new MyDelegate();
}
}
public class MyDelegate : WKNavigationDelegate
{
public override void DecidePolicy(WKWebView webView, WKNavigationAction navigationAction, Action<WKNavigationActionPolicy> decisionHandler)
{
if(navigationAction.NavigationType == WKNavigationType.Other)
{
if(navigationAction.Request.Url != null)
{
//do something
}
decisionHandler(WKNavigationActionPolicy.Cancel);
return;
}
decisionHandler(WKNavigationActionPolicy.Allow);
}
}
}
Android
[assembly: ExportRenderer(typeof(Xamarin.Forms.WebView), typeof(MyRenderer))]
namespace FormsApp.Droid
{
class MyRenderer : WebViewRenderer
{
public MyRenderer(Context context):base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.WebView> e)
{
base.OnElementChanged(e);
if (Control != null)
{
Control.SetWebViewClient(new MyClient());
}
}
}
public class MyClient : WebViewClient
{
public override bool ShouldOverrideUrlLoading(Android.Webkit.WebView view, IWebResourceRequest request)
{
//do something
return true;
}
}
}
Refer to
https://stackoverflow.com/a/45604360/8187800
https://stackoverflow.com/a/4066497/8187800
I have used ShellRenderer but I am unable to get the code working to add an extra space between the bottom of the screen and the icons. Here is an image:
I need to increase the space between the bottom of the screen and the tab item titles.
Here is the code that I have tried:-
namespace MyProject.Droid.CustomRenderers
{
public class CustomShellRenderer : ShellRenderer
{
public CustomShellRenderer(Context context) : base(context)
{
}
protected override IShellTabLayoutAppearanceTracker CreateTabLayoutAppearanceTracker(ShellSection shellSection)
{
return new CustomBottomNavAppearance();
}
protected override IShellSectionRenderer CreateShellSectionRenderer(ShellSection shellSection)
{
return base.CreateShellSectionRenderer(shellSection);
}
protected override IShellItemRenderer CreateShellItemRenderer(ShellItem shellItem)
{
return base.CreateShellItemRenderer(shellItem);
}
}
public class CustomBottomNavAppearance : IShellTabLayoutAppearanceTracker
{
public void Dispose()
{
}
public void ResetAppearance(TabLayout tabLayout)
{
}
public void SetAppearance(TabLayout tabLayout, ShellAppearance appearance)
{
for (int i = 0; i < tabLayout.ChildCount; i++)
{
var child = tabLayout.GetChildAt(i);
child.SetPadding(0, 0, 0, 20);
}
}
}
}
Let me know how can I fix this. Thanks!
I have a page where the idea is to use it with external keyboards. When the page loads, I set the focus on an Entry control and I want to hide the soft keyboard.
This is the class where I want to do that:
internal class RedactContent : ContentPage
{
StackLayout stack = new StackLayout();
Entry entry;
internal RedactContent()
{
entry = new Entry();
Content = new StackLayout
{
Children = {
entry,
//more code
}
};
}
protected override void OnAppearing()
{
base.OnAppearing();
entry.Focus();
// Hide Keyboard
}
}
How can I do that?
It is possible to create CustomEntry with CloseKeyboard method. For this you need to write custom renderers for each platform. See http://developer.xamarin.com/guides/cross-platform/xamarin-forms/custom-renderer/
On Android your CustomEntry class could look like this:
[assembly: ExportRenderer(typeof(CustomEntry), typeof(CustomEntryRenderer))]
public class CustomEntryRenderer : EntryRenderer
{
public CustomEntryRenderer()
{
HideKeyboard();
}
void HideKeyboard()
{
this.Control.InputType = 0;
InputMethodManager inputMethodManager = this.Control.Context.GetSystemService(Context.InputMethodService) as InputMethodManager;
inputMethodManager.HideSoftInputFromWindow(this.Control.WindowToken, HideSoftInputFlags.ImplicitOnly);
}
// ...
}
* First create a derivated class from Entry
public class KBLessEntry : Entry
{
public KBLessEntry() : base()
{
}
}
* Then create a custom platform EntryRender
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using MobileClients.Droid.Core;
using Android.Views.InputMethods;
using System;
using System.ComponentModel;
[assembly: ExportRenderer(typeof(KBLessEntry), typeof(KBLessEntryRender))]
namespace MobileClients.Droid.Core
{
public class KBLessEntryRender : EntryRenderer
{
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
Control.InputType = 0;
try
{
// Hide keyboard
InputMethodManager inputMethodManager = this.Control.Context.GetSystemService(Android.Content.Context.InputMethodService) as InputMethodManager;
if (inputMethodManager != null)
{
inputMethodManager.HideSoftInputFromWindow(this.Control.WindowToken, HideSoftInputFlags.None);
}
}
catch(Exception Ex)
{
}
}
}
}
And in XAML
<local:KBLessEntry x:Name="TxtCode" FontSize="18" Placeholder="Código producto" TextColor="Black" HorizontalOptions="FillAndExpand"></local:KBLessEntry>
local: must be defined has a namespace in your xaml xmlns:local="clr-namespace:MobileClients.Droid.Core;assembly=MobileClients.Droid" where the derivated Entry class (in this case KBLessEntry) resides
And thats it
View view = ActivityCreateAccount.this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)
getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
I currently have a gridview that is populated via database through a c# method.
I wanted to know if there was a way to select the row when clicked anywhere on the row and not use the select button altogether. And then have the information from that row be sent back and populate another area on the webpage.
Is there a grid better than gridview for this? Should I outsource to jQuery? Or is gridview all I should need?
what you need to do is develop a row-clickable GridView. Best bet is to follow the instructions in the link. If your okay with VB, you can go along that route. A user has also converted it into C#, its in the comments section. Ill include it incase you dont see it.
Heres a link I have saved: http://aspadvice.com/blogs/joteke/archive/2006/01/07/14576.aspx
using System;
using System.ComponentModel;
using System.Configuration;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CustomGridView
{
/// <summary>
/// Summary description for ClickableGridView
/// </summary>
public class ClickableGridView : GridView
{
public string RowCssClass
{
get
{
string rowClass = (string)ViewState["rowClass"];
if (!string.IsNullOrEmpty(rowClass))
return rowClass;
else
return string.Empty;
}
set
{
ViewState["rowClass"] = value;
}
}
public string HoverRowCssClass
{
get
{
string hoverRowClass = (string)ViewState["hoverRowClass"];
if (!string.IsNullOrEmpty(hoverRowClass))
return hoverRowClass;
else
return string.Empty;
}
set
{
ViewState["hoverRowClass"] = value;
}
}
private static readonly object RowClickedEventKey = new object();
public event GridViewRowClicked RowClicked;
protected virtual void OnRowClicked(GridViewRowClickedEventArgs e)
{
if (RowClicked != null)
RowClicked(this, e);
}
protected override void RaisePostBackEvent(string eventArgument)
{
if (eventArgument.StartsWith("rc"))
{
int index = Int32.Parse(eventArgument.Substring(2));
GridViewRowClickedEventArgs args = new GridViewRowClickedEventArgs(Rows[index]);
OnRowClicked(args);
}
else
base.RaisePostBackEvent(eventArgument);
}
protected override void PrepareControlHierarchy()
{
base.PrepareControlHierarchy();
for (int i = 0; i < Rows.Count; i++)
{
string argsData = "rc" + Rows[i].RowIndex.ToString();
Rows[i].Attributes.Add("onclick", Page.ClientScript.GetPostBackEventReference(this, argsData));
if (RowCssClass != string.Empty)
Rows[i].Attributes.Add("onmouseout", "this.className='" + RowCssClass + "';");
if (HoverRowCssClass != string.Empty)
Rows[i].Attributes.Add("onmouseover", "this.className='" + HoverRowCssClass + "';");
}
}
}
public class GridViewRowClickedEventArgs : EventArgs
{
private GridViewRow _row;
public GridViewRowClickedEventArgs(GridViewRow aRow)
: base()
{
_row = aRow;
}
public GridViewRow Row
{
get
{ return _row; }
}
}
public delegate void GridViewRowClicked(object sender, GridViewRowClickedEventArgs args);
}
I have designed a custom panel which can expand or collapse form at run time.
When I change its height from custom designed task, it does not update it.
Code of my control class:
using System;
using System.Windows.Forms;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Windows.Forms.Design;
[Designer(typeof(MyControlDesigner))]
public partial class ExpandCollapsePanel : UserControl
{
private bool flag = false;
private Size size;
public int usrVerticalSize;
public ExpandCollapsePanel()
{
InitializeComponent();
}
[DefaultValueAttribute(true)]
public int SetVerticalSize
{
get
{
return usrVerticalSize;
}
set
{
usrVerticalSize = value;
}
}
Code of taskpanedesign class:
namespace ExpandCollapseFormLibrary
{
class CustomDialogue : ControlDesigner
{
private DesignerActionListCollection actionLists;
public override DesignerActionListCollection ActionLists
{
get
{
if (actionLists == null)
{
actionLists = new DesignerActionListCollection();
actionLists.Add(new MyActionListItem(this));
}
return actionLists;
}
}
}
internal class MyActionListItem : DesignerActionList
{
public MyActionListItem(ControlDesigner owner) : base(owner.Component)
{
}
public override DesignerActionItemCollection GetSortedActionItems()
{
var items = new DesignerActionItemCollection();
//items.Add(new DesignerActionTextItem("Hello world", "Misc"));
items.Add(new DesignerActionPropertyItem("Checked", "Vertical Drop Down Size"));
return items;
}
public int Checked
{
get { return ((ExpandCollapsePanel)base.Component).SetVerticalSize; }
set { ((ExpandCollapsePanel)base.Component).SetVerticalSize = value; }
}
}
}
When I change the value the Form1(where drag and dropped) designed class keep it permanently.
the SetVerticalSize property value of your custom pane's is really changed, but the problem is that the designer host does not know about it at all. To notify the designer host about your custom pane changing you should implement something like this (I suggest you read the IComponentChangeService MSDN article for more details):
int usrVerticalSize;
[DefaultValue(true)]
public int SetVerticalSize {
get { return usrVerticalSize; }
set {
FireChanging(); //changing notification
try {
usrVerticalSize = value;
}
finally { FireChanged(); } //changed notification
}
}
void FireChanging() {
IComponentChangeService service = GetComponentChangeService();
if(service != null)
service.OnComponentChanging(this, null);
}
void FireChanged() {
IComponentChangeService service = GetComponentChangeService();
if(service != null)
service.OnComponentChanged(this, null, null, null);
}
IComponentChangeService GetComponentChangeService() {
return GetService(typeof(IComponentChangeService)) as IComponentChangeService;
}