Xamarin back button Accessibility Name in iOS and Android - c#

In Xamarin Forms if you activate the navigation bar, that show you the title of the page and an arrow to use as a back button, when you have the screen reader activated and the back button is on focus, the talkback (for Android) says "unlabeled button".
I know how to set the Accessibility Name of general elements, but I don't know how to get the back button element, since it is not an istance.

If you're using Shell Navigation, create a CustomShellRenderer
[assembly: ExportRenderer(typeof(AppShell), typeof(CustomShellRenderer))]
namespace Droid.Renderers.CustomAppShell
{
public class CustomShellRenderer : ShellRenderer
{
protected override IShellToolbarAppearanceTracker CustomToolbarAppearanceTracker()
{
return new CustomShellToolbarAppearanceTracker(this);
}
}
}
namespace Droid.CustomShell
{
public class CustomShellToolbarAppearanceTracker : ShellToolbarAppearanceTracker
{
public override void SetAppearance(AndroidX.AppCompat.Widget.Toolbar toolbar, IShellToolbarTracker toolbarTracker, ShellAppearance appearance)
{
base.SetAppearance(toolbar, toolbarTracker, appearance);
toolbar.NavigationContentDescription = "Custom Label Description”; // Set label here
}
}
}

Related

Detecting tab changed event

I am working on xamarin.forms. I need to detect the event of tab being changed either by swapping left or right or by clicking without using custom renderer
I tried below event but it is firing in both cases when child page being pushed or tab being changed. how can i get isolated event of tab being changed
public class MyTabbedPage : TabbedPage
{
public MyTabbedPage()
{
this.CurrentPageChanged += CurrentPageHasChanged;
}
protected void CurrentPageHasChanged(object sender,EventArgs e)
{
var pages= Navigation.NavigationStack;
if (pages.Count > 0)
{
this.Title = pages[pages.Count - 1].Title;
}
else
this.Title = this.CurrentPage.Title;
}
}
This issue I am facing is: In below screenshot part1 is Homepage(title="Diary") & part2 is Childpage(title="Homework") when I change tab & again come to first tab than navigationbar title getting changed "Homework" to "Diary"(Screeshot2)
As you are on your tabbed page already you can literally just do the following
public partial class MyTabbedPage : TabbedPage
{
public MyTabbedPage()
{
InitializeComponent();
CurrentPageChanged += CurrentPageHasChanged;
}
private void CurrentPageHasChanged(object sender, EventArgs e) => Title = CurrentPage.Title;
}
if you want to use the sender you can do the following
public partial class MyTabbedPage : TabbedPage
{
public MyTabbedPage()
{
InitializeComponent();
CurrentPageChanged += CurrentPageHasChanged;
}
private void CurrentPageHasChanged(object sender, EventArgs e)
{
var tabbedPage = (TabbedPage) sender;
Title = tabbedPage.CurrentPage.Title;
}
}
Or if you can elaborate on what you are trying to do exactly I can give a better answer as I do not know what it is that you are trying to do exactly
I don't think you can achieve what you want to do, at least not like this. The event behaves the way it does and as described: it is fired whenever the current page changes, also for children.
That being said, I think you should focus on implementing the functionality you want with the tools we have. I can't really deduce from your code what you are trying to do, but it looks like you want to change the title? When a tab is changed? Why not just make some kind of condition to only do it for certain pages? For example when the page is contained in the Children collection?

how to pass data from one window to another?

I am working on C# wpf, and I am trying to create 'favorite' function on it.
There is one window called 'favorite' and it is where a user can save his data.
Another window is 'MainWindow' and I want to load the data here.
There are two buttons and two textbox in 'favorite'.
If I type words in each box, I hope they can be saved if I click star1button.
And if I type another words in each box, I hope they would be saved if I click star2button.
So I hope each data will be stored separately, without being overlapped.
And then, if I press button1 on 'mainwindow', I hope those words of star1button would show up in textboxes of mainwindow.
And if I press button2 on mainwindow, I hope words of star2button would show up in textboxes of mainwindow.
Thanks in advance!!
You can place an attribute in your App.xaml.cs which should be accessible from both
namespace MyApp
{
sealed partial class App : Application
{
public string myValue;
// the rest of your App.xaml.cs code
}
}
Then in your MainWindow and other window put this code
public string MyValue
{
get
{
return (Application.Current as MyApp.App).myValue;
}
set
{
(Application.Current as MyApp.App).myValue= value;
}
}
You can use a static class to pass values between windows.
public static class CurrentParameters
{
public static string mySharedValue { get; set; }
}

Hide WinForm UserControl custom property from VS designer

Visual Studio is incorrectly calling my UserControl's custom properties at design time.
I have read many of the posting about using the [Browsable( false )] and [DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden )] attributes, but this has not worked for me.
To reproduce this problem, using Visual Studio, create a new Windows Forms Application, then add a User Control to your project, and drag that User Control onto your Form. Add a public custom property to your User Control, as shown below.
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
}
[Browsable( false )]
[DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden )]
public bool AreYouThere
{
get
{
MessageBox.Show( "Yes I Am Here!" );
return true;
}
}
}
When the Form is open in the Visual Studio designer, if I force the solution to clean and then rebuild, I will see a MessageBox with the text "Yes I Am Here!", indicating that Visual Studio has called the AreYouThere property on my User Control.
This should not happen, since I have decorated the AreYouThere property with the [Browsable( false )] and [DesignerSerializationVisibility( DesignerSerializationVisibility.Hidden )] attributes.
Any idea why this is happening?
(This problem occurs on Visual Studio 2010 and 2013).
In order to hide a property from every place possible you have to mark it with those attributes
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
[EditorBrowsable(EditorBrowsableState.Never)]
[Bindable(false)]
[Browsable(false)]
public class CustomDesigner : ControlDesigner
{
private static string[] RemovedProperties = new[]
{
"AccessibilityObject","AccessibleDefaultActionDescription","AccessibleDescription",
"AccessibleName","AccessibleRole","AllowDrop","Anchor","AutoEllipsis","AutoScrollOffset",
"AutoSize","AutoSizeMode","FlatAppearance", "FlatStyle",
"TextAlign","TextImageRelation","UseCompatibleTextRendering",
"UseMnemonic","UseWaitCursor"
};
public CustomDesigner() { }
protected override void PreFilterProperties(IDictionary properties)
{
foreach (string prop in RemovedProperties)
{
properties.Remove(prop);
}
base.PreFilterProperties(properties);
}
}
[ToolboxItem(true)]
[DesignerCategory("code")]
[Designer(typeof(CustomDesigner))]
public partial class NewButton : Button
{
public Color OnHoverBackColor
{
get { return _onHoverBackColor; }
set
{
_onHoverBackColor = value;
Invalidate();
}
}
}
Do not set the default value for the property as you want it. In your example, set the property AreYouThere to false/true and in the parent or whereever you are using it you instanceOfUserControl1.AreYouThere = true/false in say Load event.

Setting default properties for toolbox items?

I don't want the button I add to have dotted borders when clicked, so I found out that I can disable that by turning off the focus cues. I don't want to have to change settings like this for each individual button I add. Is there any way to set property defaults in Visual Studio?
What you need to do is create a new Control based on Button and use it throughout your application.
public class MyButton : System.Windows.Forms.Button
{
protected override bool ShowFocusCues
{
get { return false; }
}
}

Merging MDI toolbar

In .net MDI application the menu of child form automatically is merged to the menu of parent form.
Is there a way to do similar thing with the tool bars.The concept is to send the toolbar of active child to the parent toolbar stripe.
I found http://community.devexpress.com/forums/p/5696/24663.aspx but could not achieve it.
It can be done if following way .
More detail could be found in this blog. Both forms should have a toolstrip.
//In Parent form
protected override void OnMdiChildActivate(EventArgs e)
{
base.OnMdiChildActivate(e); //REQUIRED
HandleChildMerge(); //Handle merging
}
private void HandleChildMerge()
{
ToolStripManager.RevertMerge(tsParent);
IChildForm ChildForm = ActiveMdiChild as IChildForm;
if (ChildForm != null)
{
ToolStripManager.Merge(ChildForm.ChildToolStrip, tsParent);
}
}
public partial class frmChild : Form, IChildForm
{...}
interface IChildForm
{
ToolStrip ChildToolStrip { get; set; }
}

Categories

Resources