Setting InputAccessoryView into UISearchController - c#

I'm currently trying to extend my Xamarin.Forms app with search bars in the navigation bar by this guide: https://codetraveler.io/2019/10/05/adding-a-search-bar-to-xamarin-forms-navigationpage/
So far it works great. But now I also want to add custom action to the keyboard based on what is available on this page. But it seems like the InputAccessoryView has no available setter for the UISearchController. So how can I set those custom actions and a Done button to it? Is there some other way to add this? Or is it maybe a bug by Xamarin that the InputAccessoryView is not setable?

nvm sometimes a bit of sleep helps a lot. The InputAccessoryView needs to be set on the SearchBar within the UISearchController of course and not directly on the UISearchController...

Related

How to change TabBarItem style or cancel default function (Xamarin forms iOS and Android)

In my case, my tabbar items are Navigation Pages which in some cases may or may not be in a stack, ie it may be that the current page of this stack is not the first Page, the default function of tabbar item takes me straight. for the first item in this stack, which is very bad for my users.
Is it possible to modify this? Cancel navigation when you click on the tabbar item or something that solves this problem?
Alternatively, I was implementing a CustomRenderer that turned off (Enable = false) in UITabBarItem, it works but changes the style and this is not cool in my case, I tried in many ways to override the Disable state and could not.

what the equivalent to OnResume on Xamarin.forms

Right now, I am using Xamarin.Forms PLC project.
I have a label[x] on Page[x], then I will press button and go to Page[xx] ,then I will go back to Page[x] but I need to update Label[x] Text upon some Choices selected on Page[xx].
Which Event should i use to update Label.Text?
I was overriding OnResuem()Function on Xamarin.android, but it is not working on Xamarin.forms, I have no idea which is the best solution.
Some quick solution for this is:
-overriding the OnAppearing() method of the page and change the label.Text property once you change it on the other page
-Change the property to be public and change it on the other page
-Send the property to the next page as a parameter
but what you should do! is bind your property to a ViewModel and use OnPropertyChange() (Xamarin.Forms way and MVVM architecture) Events: a couple of tutorials how to understand this better:
https://blog.xamarin.com/advanced-data-binding-for-ios-android-and-windows/
https://developer.xamarin.com/guides/xamarin-forms/user-interface/xaml-basics/data_bindings_to_mvvm/
https://developer.xamarin.com/guides/xamarin-forms/user-interface/xaml-basics/data_binding_basics/
I'm not sure how youre code works because you havent said. So I'm not sure how Page[x] knows about Page[xx] but it sounds to me like you want to use the OnAppearing() override.
Which from the Xamarin.Forms Page API documentation states:
When overridden, allows application developers to
customize behavior immediately prior to the Page becoming visible.
You could do this by adding the following to your Page[x].xaml.cs file
protected override void OnAppearing()
{
//Your code here
}

UITextView - InsertText doesn't auto-correct or auto-capitalize

I have a custom InputView on a UITextView with auto-correct and auto-capitalization turned on.
My custom input view has a bunch of UIButtons that call InsertText on the UITextView. This works fine for inserting text at the current cursor position. The problem is that auto-correction and auto-capitalization do not work when InsertText is called. If input comes in through a bluetooth keyboard, or the standard keyboard, everything works fine.
Is there some method I can call on UITextView to invalidate auto-correct/auto-capitalization? SetNeedsDisplay was my first attempt, but it had no effect. Also, my app may potentially be iOS 7 and higher, so it's fine to use newer text APIs.
*NOTE: I'm using MonoTouch (Xamarin.iOS), but Objective-C answers are welcome.
Not without rolling your own autocorrect system. The iOS autocorrect system is opaque to developers, and only works on keyboard input. Any time you explicitly set the .text property on an input or text view, the value you set is what will appear.
Ok, I found a way in which this works:
Implement your own NSTextStorage
Setup an NSLayoutManager and NSTextContainer to coordinate your NSTextStorage with UITextView
When programmatically modifying your NSTextStorage subclass, auto correct "just works"
I think this works because modifying NSTextStorage fires events that notify the UITextView to update things like autocorrect. It works only on iOS 7 and higher.

WPF Frame control , how to use it with usercontrols?

I need to build some kind of phone emulator to test our webservice and have a general idea how the flow will go.
Doesn't needs to be anything fancy.
Now I made a WPF form with a phone image in it. In the display of the phone I have placed a frame. That looks good so far :)
But what now? How can I fill the frame with say the startscreen? Do I need to create a usercontrol for each page I want to view or show? Or is there another approach?
And how about databinding? I want to use MVVM, so I need to create a viewmodel for each usercontrol like we do normally? Or a viewmodel for each page?
I just discovered the WPF Frame Control and it seems there's not so much info on the net to find, or not what I want.
Thx for any pointers in the right direction.
Here is an image how it now looks:
For each view (screen) that the end user is going to see you will need to make a page that will hold all your logic and functions per page. All you do in Cycle through the pages in your own way.
FrameName.Navigate(PageName);
Remember to initialize the pages before you can use them. You can intialize them when you use the Navigate function like:
FrameName.Navigate(new PageName());
This works well for smaller projets, bigger projects you might want to use some clever way of initializing the pages because you navigate, like:
if(TimeToLoadPage == True)
{
PageName pagename = new PageName();
RunPageNavigation()
}
public Void RunPageNavigation()
{
FrameName.Navigate(pagename);
}
You can data bind the width and height of the page by inheriting from the Frame (Going through Ancestry route). You can do all the content based stuff in a page exactly the same as a window. You can't however control the page like a window.
Hope this helps a bit more.

Access Pivot Control from App.xaml.cs

In my MainPage.xaml, I created a Pivot Control: <controls:Pivot Title="Powder God" Name="PivotControl">.
My first pivot view is a HubTile that summarize all other individual pages. So my application bar will be different between the first pivot view and all other ones.
That's why I put my application bar in App.xaml's resource section, then load based on selected index of my pivot.
My question is:
In the application bar I will be using for all individual pages, I want to have a delete option, where I will remove that specific item (a view model) from my data context.
I know I can use PhoneApplicationFrame root = Application.Current.RootVisual as PhoneApplicationFrame; to access navigation services, but I don't know how can I reference to my pivot, so that I can get the selected index and proceed forward.
Thanks!
Using MVVM you SHOULDN'T do this:
((PageType)Application.Current.RootVisual).PivotControl. //Blah
PageType is whatever type PhoneApplicationFrame is that contains your PivotControl. If this doesn't work you need a Property in the RootVisual
PAGE
public Pivot MyPivot
{
get
{
return PivotControl;
}
}
APP
((PageType)RootVisual).MyPivot. //Blah
On one level Microsoft's suggestion of putting the ApplicationBar in App.xaml is great as it can be referenced from everywhere and would appear to encourage code reuse: however this question highlights the limit to this approach. An application bar is typically used to provide actions which are specific to the current page (or pivot item) and just because the buttons are the same you may not want the exact same code to run in each case.
In this case I think it would better to create a factory method that creates your common ApplicationBar with the click handlers you specify specific to your page/pivot item. For bonus points put the method in a new class (not App) so it doesn't get lost in all the boilerplate code there. Call this factory method in your page constructor and remember your ApplicationBar in your class. For multiple app bars, create them all up front and you can then easily switch between these app bars in your Pivot SelectionChanged code.
The alternative of creating the ApplicationBar in App.xaml and then retrieving this from the App.xaml.cs "Resources" ResourceDictionary in code, modifying the click callbacks, is more complicated in my opinion.
I wish they'd done a better job of implementing the ApplicationBar so people wouldn't want to do this. I've found that using the ApplicationBar forces you to add code to your Page.xaml.cs even if you use a framework like MVVM Light. This is still OK in MVVM as it's UI specific code that belongs in the View, but it makes things inconsistent if you're using ICommand everywhere else. Last time I decided it was better to create the entire ApplicationBar in code rather than hack this kind of thing via App.xaml.cs.
Update: There is a UserVoice request for a data bindable ApplicationBar.

Categories

Resources