FormsAppCompatActivity and custom ActionBar/ToolBar - c#

I am working on a Xamarin.Forms app, where I was using a FormsApplicationActivity as my main activity and was able to customize the ActionBar with a custom view inside it (I put a Spinner in it, for some page)
But since there was a few UI / look and feel issues I upgraded to FormsAppCompatActivity.
Since I did that I just CAN'T get my spinner in the toolbar / actionbar! No matter what I try!
This was basically the previous code, wroking with FormsApplicationActivity
var activity = (Activity)this.Context;
var bar = activityActionBar;
var dlp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
bar.CustomView = new Android.Widget.Button(activity) {
Text = "Click",
LayoutParameters = dlp,
};
bar.DisplayOptions = ActionBarDisplayOptions.ShowCustom;
What should I write to support FormsAppCompatActivity please?

When using FormsAppCompatActivity the NavigationRenderer on android creates a new toolbar internally. It is a private field so far I can see and cannot be accessed.
here is the code : https://github.com/xamarin/Xamarin.Forms/blob/d1a8477233b28e6a20c6f5d4a75128ec2a05e6dc/Xamarin.Forms.Platform.Android/AppCompat/NavigationPageRenderer.cs
See image for the specific code part. I am also trying now to get access to view. So just a note the action bar you are trying to edit is the wrong one. That one is created on activity startup.
UPDATE: maybe found a solution look here : https://forums.xamarin.com/discussion/69923/access-to-the-formsappcompatactivity-bar

Related

Show DevExpress waitform dialog without designer

I'm trying to display a Loading Please Wait dialog form using devex controls and I can't seem to do it. (using winforms, c#)
I'm using an older version of devex - not the latest. I can't do
SplashScreenManager.ShowDefaultWaitForm()
I need to do this in code without the designer.
1.
I tried:
SplashScreenManager.ShowForm(typeof(WaitDialogForm));
It looks right when it loads, but then it throws an error:
Unable to cast object of type 'DevExpress.Utils.WaitDialogForm' to type 'DevExpress.XtraSplashForm.SplashFormBase'
I tried:
SplashScreenManager.ShowForm(typeof(WaitForm));
This shows an empty form thats too big with no image and no text
I tried:
WaitDialogForm mWaitDialog = new WaitDialogForm() {Visible = false};
mWaitDialog.Show();
The wait form doesn't look right. There are white spaces instead of the image.
I tried:
WaitDialogForm mWaitDialog = new WaitDialogForm() {Visible = false};
mWaitDialog.ShowDialog();
The code doesn't continue executing.
I saw examples of
SplashScreenManager.ShowForm(typeof(WaitForm1));
I don't know how to do this without designer.
Can somebody please assist? I thought I'm doing something simple, but I can't seem to figure it out!
Probably this help u ;)
using (new DevExpress.Utils.WaitDialogForm("Please wait"))
{
//Do your stuff here
}
I don't know if this is in your 13.2 version but from looking at documentation you should be using ShowWaitForm instead of just ShowForm.
SplashScreenManager ssm = new SplashScreenManager();
ssm.ActiveSplashFormTypeInfo = typeof(WaitForm1);
ssm.ShowWaitForm();
If that does not work then i would just try preparing a working solution in the designer and then extracting the code from the designer.cs file.
Found a specific documentation example here

Custom DataType for Umbraco containing MultiUrlPicker

I am trying to create a custom DataType for Umbraco containing group of elements which include a TextBox, MediaPicker and a MultiUrlPicker. I can create a Text Box using the following snippet:
var textBox = new TextBox();
and a Media Picker using the following snippet:
var mediaPicker = new SimpleMediaPicker();
The above two work fine but struggling with how to add MultiUrlPicker in my custom control. I am trying to use the uComponnents package of Umbraco and it provides MultiUrlPickerDataType and MultiUrlPickerDataEditor classes but I am struggling to how to initiate and insert these into my control.
I made it work finally using the following code:
var urlPicker = new MultiUrlPickerDataEditor {Settings = new MultiUrlPickerSettings{ Standalone = false }};
Posting it here, in case anyone else ever struggle with the same thing.

Obtain current page name in Xamarin Forms app

I am currently trying to understand how to get the name of the (xaml) page I am currently into, with my Xamarin Form app.
How am I supposed to do it? I tried a variety of cases, even looking around the Internet, but nothing actually worked for me so far :/
This is just C# reflection - the name of the XAML page should match the name of it's class
var name = this.GetType ().Name;
You would (commonly) use wither a one page app (master/detail, tabs page) or a set of navigable pages, managed by a NavigationPage.
App.Current.MainPage would (normally) contain the first page shown and if it has .Navigation that would be the NavigationPage that can give you the most recently shown page - last one in the stack. If it doesn't you could assume your app being one page app.
All of the above is just "common" and not necessarily true in all cases, but gives you a starting point where to look for your current page.
var actionPage = App.Current.MainPage;
if (actionPage.Navigation != null)
actionPage = actionPage.Navigation.NavigationStack.Last();
actionPage.DisplayActionSheet(...)
I know that this has been resolved and the scenario is somewhat different but in my specific case I needed to identify the current page in the navigation stack from platform specific code so just in case it may help someone else, this is the code I used:
I used the title property that was set in the constructor of the page.
public static string GetCurrentPage()
{
var page = App.Navigation.NavigationStack.Last();
return page.Title;
}
You can get current open page.
1) if it's MainPage.
-> var MainPage = App.Current.MainPage as PageName;
2) if it's Navigation page.
you can get count pages.
App.Current.MainPage.Navigation.ModalStack.Count
var page= App.Current.MainPage.Navigation.ModalStack.LastOrDefault() as
PageName;
App.Current.MainPage.Navigation.NavigationStack.Count
var page1=App.Current.MainPage.Navigation.NavigationStack.LastOrDefault() as
PageName;
Here's how you can get the current page type from anywhere in the app (Xamarin Forms).
This might be a more general answer to your question but I thought it's worth posting.
If you're using:
1.App with Tabs/One Page
var mainPage = App.Current.MainPage as Xamarin.Forms.Shell;
var currentPage = mainPage.CurrentPage;
var type = currentPage.GetType().Name;
Also, URL of the current page:
string location = mainPage.CurrentState.Location.ToString()
2.Navigation Based Apps
As others also mentioned:
var mainPage = App.Current.MainPage;
var currentPage = mainPage.Navigation.NavigationStack.Last();
Hope it helps.

Failure to bind StringElement.Visible to boolean property in ViewModel

In my Xamarin Studio project on Mac, I am using MvvmCross version 3.0.13 from MvvmCross-Binaries, the XS-iOS-Mac Release assemblies, and I am trying to couple my CrossUI Dialog based View with a corresponding ViewModel. Specifically, I define the Root in my dialog view like this:
var bindings = this.CreateInlineBindingTarget<ViewModel>();
Root = new RootElement("New Connection") {
new Section {
new StringElement("Test")
.Bind(bindings, element => (object)element.SelectedCommand, vm => vm.TestConnection)
},
new Section {
new StringElement ("Add")
.Bind (bindings, element => element.Visible, vm => vm.CanAddConnection)
.Bind (bindings, element => (object)element.SelectedCommand, vm => vm.AddConnection)
}
};
In the ViewModel, CanAddConnection is set to true by the TestConnection command if test is successful.
When I run this (in the iOS Simulator) and open the dialog, the Test button is displayed and the Add button is hidden (as intended). When I click the button and the test is successful, the Add button is however not displayed, but instead I get this message in the application output:
How did this happen - CurrentAttachedCell is a child of a non-UITableView
Why is my Visible binding not working?
As far as I can tell, I have not made any code customizations upstream that would lead to this failure in the code (but I might be missing something).
If I bind CanAddConnection to another element property, for example Caption, the boolean value is properly updated in the view.
I think you are probably falling foul of an ios7 change which is addressed as part of https://github.com/MvvmCross/MvvmCross/issues/467
This fix will be included in 3.0.14 (hopefully in the next week) - in the meantime, the easiest workaround is probably to patch UpdateVisibility yourself in your own build - or to implement a custom StringElement

Sharepoint - upgrade webpart properties

I'm playing with SharePoint 2010 now and have a problem.
There is a feature that is responsible for webparts - it's scope is web. It's needed to update some properties of already created webparts, for example - title.
So I've overridden FeatureUpgrading event and added custom upgrade action into feature manifest - there is no problem here.
In that feature receiver I plan to have a code that should get the file with needed page, check it out, iterate through all the web parts on it, change property and then check in page back.
The problem is that all my webparts appear as ErrorWebPart with empty title.
By the way, if I use the same code in FeatureDeactivating event - everything works good.
The only difference I've noticed - in featureupgrading HttpContext.Current was null. So I've populated it manually but it didn't help.
While googling, the only two advices were: populate HttpContext and ensure that libs with webparts are in GAC. Both conditions are done in my situation.
The sample code from FeatureUpgrading is as proper:
SPUtility.ValidateFormDigest();
web.AllowUnsafeUpdates = true;
var request = new HttpRequest("", web.Url, "");
HttpContext.Current = new HttpContext(request, new HttpResponse(new StringWriter()));
HttpContext.Current.Items["HttpHandlerSPWeb"] = web;
var fileUrl = web.Url + "/pages/sample.aspx";
var file = web.GetFile(fileUrl);
if (file.CheckOutType == SPFile.SPCheckOutType.None)
{
file.CheckOut();
}
using (var webPartsManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared))
{
foreach (WebPart webPart in webPartsManager.WebParts)
{
Console.WriteLine(webPart.GetType().ToString());
}
}
file.CheckIn("System update");
Would appreciate any help. Maybe there is something I'm missing or there is another variant to accomplish described task?
Regards.
Since it is working on Deactivating(), I think the order in which the features are activated is the problem.
You may have to ensure the below:
1. First activate the Feature that adds the webparts
2. Then activate the new feature.
You can change this in package. Or better add a dependency to your new feature.

Categories

Resources