Xamarin.Forms/FreshMVVM - Yes/no style popup - xamarin

This is probably a quite silly question, but it nonetheless needs an answer:
I have created a small, custom MessageBox for my Xamarin.Forms project using Rg.Plugins.Popup - however, when trying to extend it to include a confirmation modal, I cannot find a way to detect whether the user has confirmed or cancelled the action from the popup.
Here's the code to open the popup
Message msgBox = new Message(); /*new instance of my Message wrapper class*/
msgBox.State = "msg_info";
msgBox.MessageTitle = "My_Message_Title";
msgBox.MessageText = "My_Message_Caption";
await CoreMethods.PushPopupPageModel<MessageBoxPageModel>(msgBox); /*using the FreshMVVM.Popup extension to navigate to the popup*/
/*need to check for confirmation here and delete the line or do nothing*/
So what I'm looking for, in short, is the appropriate way to detect whether the user has tapped the "Yes" or "No" button on the popup so I can, for example, delete a row from my database or not.
I looked into MessagingCenter but that seems to work from ViewModel to View, not ViewModel to ViewModel - Rg.Plugins.Popup suggest using a CallbackEvent, but CallbackEvents are, or so I've understood, not compatible with FreshMVVM/the MVVM pattern.

Just so this isn't kept open:
I ended up using a DevExpress Popup control as a Yes/No dialog - slightly less customization, but much more straightforward to use since I already had the DevExpress controls loaded.
Detail link for the DevExpress Popup control for those interested
https://docs.devexpress.com/MobileControls/DevExpress.XamarinForms.Popup.DXPopup

Related

Xamarin master detail page with static header and context menu

I need to do a master detail layout page in Xamarin which then will be used in child pages.
Please check the screenshot below:
I need to have a header part with button for notifications and a button for context menu plus a header.
What is the best approach how I can create this layout in Xamarin?
I will assume that you want to use Xamarin.Forms, instead of using Xamarin.Android and Xamarin.iOS separately.
One approach would be to use default MasterDetailPage as described here or even better to try it with Shell as described here.
Then, you would need to create your CustomNavigationPage and write a custom renderer for it.
Second approach would be to do some tricks, again creating your CustomNavigationPage with template(so that the navigation bar is always displayed) and that you change content dynamically.
Also, you would need to hide default navigation bar and attach click events to your menu button to really open up the menu.
Hope you got it clearly.
MasterDetailPage already provides nearly all functionality that you have asked for, so in some way your question isn't quite clear as you already mention MasterDetailPage. The only remaining problem I can see is how to set up a custom header, and that is than with NavigationPage.TitleView.

Buttons in a view in Dynamics 365

I am new with Dynamics 365 and are not sure of how I can achieve this.
I am looking into having some buttons in a view.
Maybe a view isn't the best way of doing it, but what I want to do is to have a list of records connected to the logged in user (similar to a view)
But on each row/record I want to have multiple buttons. These buttons can be like 'Complete' (Changes status on task and updates the view) , 'Send email'(Starts a workflow) and so on.
What are some of the ways of doing this? Either with Javascript/C#/plugin or something else.
You cannot add buttons in views/subgrids directly.
That’s when we add ribbon/command bar buttons using Ribbon workbench usually.
Create a Workflow Short Cut Ribbon Button (No Code Solution!)
Update:
There is a PowerApps Components Framework (PCF - preview) coming out soon, then we can build custom grid control with the layout/buttons we want.
This can be achieved with RibbonWorkbench. My answer does not differ much with #arun vinoth answer but just added few explanation lines.
https://ribbonworkbench.uservoice.com/knowledgebase/articles/132235-create-a-workflow-short-cut-ribbon-button-no-code
If you look at view below where I have selected number of contact and then I have a Button at top "Nominieren" which is shown and clicking on it will perform whatever action is needed.
There will be java-script on click of button, from Java script you could call Action or workflow or perform operation in Java script itself.
Link for Adding new Button : https://community.dynamics.com/crm/b/crmtipsfromadeveloper/archive/2017/07/26/know-how-add-a-ribbon-button-using-ribbon-workbench
Now when you look at image below I have no contact selected and it does not show button on Ribbon.
It might be possible. I haven't tried this but you can write JavaScript for a view column now (since CRM 2016).
If you go to a view you can double click on a view column to view its properties. There are two properties you might be interested in:
Web Resource
Function
Here's a link to an MS page that explains how to use these options to add an icon. It might be possible to create a clickable button which uses CRM's WebApi to perform some actions: Docs # Microsoft

Xamarin Forms open a view without Navigation

Xamarin Forms navigation examples I see leverage a NavigationPage...
public App()
{
InitializeComponent();
MainPage = new NavigationPage(new HyperTrack2.Login());
}
and then when an event occurs to move to the next page...
async void OnLogin(object sender, EventArgs e)
{
await Navigation.PushAsync(new MapPage());
}
How can one show a view without using the NavigationPage?
Depends on what you consider a view to be.
The process you outlined in your question is the prefered way to navigate using Xamarin pages. Xamarin pages contain one or more controls, or views. Usually some layout views at the root and then they branch out as needed.
The built in navigation mechanism actually utilises the optimal native techniques for navigating inside your application and will allow you to use standard gestures and buttons for navigations, display standard toolbars and title views, etc.
I fully recommend that unless you have very specific needs, you keep using the built in navigation mechanism.
Otherwise, your other option for moving through xamarin.forms pages is by just settting the MainPage property of your Application class (called App by default)
You can either access it through Application.Current.MainPage = new MyPage(); or if writing code within the app class, directly by calling MainPage = new MyPage();
Lastly, you specifically mention showing a view and not a page. If you are talking about a single control within a page, you can either bind it's IsVisible property to some value in your ViewModel, or you can give it an x:Name="myControl" (if using XAML) or store a reference to it (if creating UI in code behind) and then do myControl.IsVisible = true/false somewhere in your code behind. This toggles the visibility of a single control, which will then become a part of your page hiearchy.
If you instead wish to display the view as a "popup" over the existing page, without it actually becoming a part of the page, there are some built in simple UI elements you can use, such as action sheet and display alert. These provide simple popup windows that offer a couple of actions or display a message.
For more complex UI, look into Nuget plugin packages, or if you prefer, you can write your own by implementing the functionality on all the target platforms you require.
I suggest looking into Acr User dialogs as it's a wonderful plugin that has served me quite well. It has a much broader set of UI elements you can use, but it still won't let you define any element that you want and display it in a popup, to do that, search for popup plugins for Xamarin.Forms. There are quite a few, but none work perfectly imho.

Dialog windows in MVC

I'd like to ask a general question about MVC and dialog windows. Although I'm not very experienced in MVC pattern I can say understand its principles. What I don't know is how to manage dialog windows using MVC. Let's have a look at the particular situation: I have a main View (Window) and the controller. In the main View a user now clicks on button or menu "Options." The Options window should be raised, of course, and display several choices for the user. But who's actually responsible for creating and showing the Options window? View sends the information to the controller that user clicked on "Options" button. But now what? Controller should create new Window by itself? I don't think so, it usually doesn't create any objects of type View. The View? I also don't think so, it cannot manage Options information from the Options window. Someone else, probably, but who... Can somebody explain me how this should work, please? My preferred programming language is C# but this is more about principles. Thank you.

Altering windows form from userControl

i'm quite new with windows forms and i have a small issue.
i have a form that contains a userControl.
the form also contains a button with enabled = false, and upon some user selection in the userControl sets the button to enabled = true.
basically, i want to know what's the best way to change something in the form upon a change in the userControl.
I saw on the internet that event/delegates might be the answer, but it seems too complicated for such a small thing.
anyone has another solution?
thanks
Bosco
Events are your friends. They're really not that complicated. Just find an apropriate event for your user selection and set the button property.
User controls are meant to be hosted by different forms or other user controls. That's why they should be decoupled from their host controls.
IMHO best way to decouple the user control from its parent is to use events. Another way would be to implement the observer pattern. Events are a special implementation of observer pattern in .NET.

Resources