After being away from Titanium for awhile, seems I forgot even the simplest tasks. Case in point: I have a stack of buttons on a main page. Each button should open its respective view when clicked. How do I open that associated view when the button is clicked?
View
<Alloy>
<Tab title="Home">
<Window class="container">
<Label>This is the Home View</Label>
<ImageView id="kplLogo"/>
<View id="homeNav">
<Button class="navButton" id="recognizeButton" title="Recognize" onClick="doClick" />
<Button class="navButton" id="reactButton" title="React"/>
<Button class="navButton" id="reportButton" title="Report"/>
</View>
</Window>
</Tab>
</Alloy>
When the user clicks a button, such as the recognizeButton for now, it should open the recognizeView. I know it's simple, but I'm having brainlock at the moment.
Thanks for the help. Ask if you need more detail.
First, add a property to each Button which will make possible to invoke the child View controllers, such as:
<Button id="recognizeButton" title="Recognize" child_controller="recognizeView" />
Also use an id on the <tab> element:
<Tab id="hometab">
Then, in the controller, add the event listener:
$.recognizeButton.addEventListener('click', function(e) {
if (e.source.child_controller) {
controller = Alloy.createController(e.source.child_controller);
$.hometab.open(controller.getView());
}
});
This will open a new window in the same tab, preserving history so that when you click reutrn, you'll be back in the main tab. If you need a broader example, check this: https://github.com/asiviero/drupanium_app/tree/master/app in which I use the home view in that manner, opening up views from controllers inside "includes" folder
Related
I need to create a "detail" page that when I clicked from my "master" page, on some button, it redirects me to that "detail" page with navigation bar which has back button.
Code for this is as follows:
protected async Task GoToPage(string route)
{
await Shell.Current.GoToAsync(route);
}
Question is: how to preserve downtab from my previous master page, to show as well as on my detail page?
design is look like this:
https://i.imgur.com/tBqHhH8.png
I only have navigation bar.
In my AppShell.xaml I defined TabBar section for my "master" page ("master" page is first in my tabbar menu).
Should I create separate TabBar for my "detail" page and somehow to insert navigation bar?
You can put your Page to the MenuItem tab.
<MenuItem Text="About"
IconImageSource="info.png"
Command="{Binding AboutPageCommand}" />
Background code.
public ICommand AboutPageCommand => new Command(async () => await NavigateToAboytPageAsync());
async Task NavigateToAboytPageAsync()
{
await Shell.Current.GoToAsync($"aboutPage");
Shell.Current.FlyoutIsPresented = false;
}
Register the page in the App.xaml.cs
Routing.RegisterRoute("aboutPage", typeof(AboutPage));
There is a property called IsTabStop you can set in the Tab tag which can preserve downtab from your previous master page:
IsTabStop, of type bool, indicates whether a Tab is included in tab
navigation. Its default value is true, and when its value is false the
Tab is ignored by the tab-navigation infrastructure, irrespective if a
TabIndex is set.
You can set it to false at specific tab to keep downtab at that tab.
Code example:
<!-- Your Pages -->
<TabBar>
<Tab Title="Master" Icon="tab_feed.png" IsTabStop="False">
<ShellContent ContentTemplate="{DataTemplate local:ItemsPage}" />
</Tab>
<Tab Title="About" Icon="tab_about.png" >
<ShellContent ContentTemplate="{DataTemplate local:AboutPage}" />
</Tab>
</TabBar>
Here is the document: shell/tabs
I don't need a MasterDetail until I've navigated through two regular ContentPages first, where I collect information that the MasterDetail will need. The ContentPages make use of the INavigationParameters sent to OnNavigatedTo and OnNavigatedFrom for that collected information.
The the SecondPage viewmodel handles a button command wherein the handler calls the MasterDetail:
NavigationService.NavigateAsync("CompareSelectionsMasterDetail/CompareSelectionsNavigationPage/RangeCircle",
parameters);
Sure enough, the RangeCircleViewModel.OnNavigatedTo receives the parameters. However, when I go back (like with the Android back button), its OnNavigatedFrom is not called, thereby sending null parameters back leaving my ContentPages with no idea what their state was.
The viewmodel for CompareSelectionMasterDetail doesn't do anything and the viewmodel for CompareSelectionsNavigationPage just does this:
public class CompareSelectionsNavigationPage : NavigationPage, INavigationPageOptions
{
public bool ClearNavigationStackOnNavigation => false;
}
I'm not sure what it means to have a NavigationPage in the MasterDetailPage XAML and the separate CompareSelectionsNavigationPage that I call with Prism but if I remove the XAML one, the RangeCircle page doesn't render. If I only have the XAML one and change the Prism navigation to CompareSelectionsMasterDetail/NavigationPage/RangeCircle then I get the same behavior as using both NavigationPages.
My MasterDetail XAML is simple.
> <MasterDetailPage.Master>
> <NavigationPage Title="Required Foo" Icon="hamburger_icon.png">
> <x:Arguments>
> <ContentPage Title="Menu">
> <StackLayout Padding="40">
> <!-- TODO: // Update the Layout and add some real menu items -->
> <Label Text="Hello John"/>
> <Button Text="Range Circle" Command="{Binding NavigateToRangeCircleCommand}" CommandParameter="ViewA" />
> </StackLayout>
> </ContentPage>
> </x:Arguments>
> </NavigationPage> </MasterDetailPage.Master>
Every example I can find of Master Detail (especially with Prism) starts off the app with Master Detail page. I'm not sure if my usage is what breaks OnNavigatedFrom? (Basically ContentPage(Page1)->ContentPage(Page2)->MasterDetail->NavigationPage->NavigationPage->ContentPage(RangeCircle))
The individual ContentPages don't have a problem calling OnNavigatedFrom.
So I am currently working with tabpane in JavaFx for the first time.
After it didn't work as expected I reduced the tabpanes content one bit at a time until it looked like this:
<ScrollPane prefWidth="Infinity" prefHeight="Infinity" fitToWidth="true" xmlns:fx="http://javafx.com/fxml"
fx:controller="de.Cos4U.ui.scene.control.CosplayView">
<VBox alignment="top_left" minWidth="200" prefHeight="200" spacing="5">
<TabPane prefHeight="Infinity" minHeight="Infinity">
<tabs>
<Tab text="Tab1">
<content>
<Label text="test"/>
</content>
</Tab>
<Tab text="Tab2">
<content>
<Label text="tests2"/>
</content>
</Tab>
</tabs>
</TabPane>
</VBox>
</ScrollPane>
After selecting "Tab2", the content area still shows the label "test". It is refreshed as soon as you scroll. It's a this simple tabpane, so why doesn't it refresh its content?
Edit: I am using 1.8u74 right now. I edited the fxml so now its as complete as needet but as reduced as possible.
The controller doesn't affect the tab pane in any way so. So far it handles simple user inputs. After removing anything i don't need for this example, it is reduced to 0.
I used to have the same problem. I don't have the exact reason why it doesn't update correctly, but if you want to force a refresh of the Layout, you can request it instead of using a workaround like changing the size.
requestLayout();
Suppose you want to set the content of a tab inside your controller.
class Panel extends TabPane {
private Tab tab;
public void setTabContent(Node container) {
tab.setContent(container);
getSelectionModel().select(tab);
requestLayout(); // to force refresh the layout
}
}
You then call this method from your controller.
My app has a WebView for displaying some contact information. It has a link to a website that I want to load externally using Device.OpenUri(). I'm using FreshMvvm and I want to intercept the Navigating event from the WebView in the ViewModel and cancel the default action which would load the external page into the WebView.
I've tried using the Corcav.Behaviors plugin which does call my ViewModel command:
<WebView
HorizontalOptions="Fill"
VerticalOptions="FillAndExpand"
Source="{Binding WebViewSource}">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand
EventName="Navigating"
Command="{Binding NavigatingCommand}"
CommandParameter="{Binding}"/> <!-- what goes here -->
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</WebView>
But I'm not sure what the CommandParameter should be - I need the URI of the link that was tapped, and I don't know how to then prevent the default behaviour from occurring.
Is this the best approach or should I be looking at an alternative?
Having revisited this recently for another project I stumbled across the answer. The updated XAML is:
<WebView
x:Name="webView"
HorizontalOptions="Fill"
VerticalOptions="FillAndExpand"
Source="{Binding WebViewSource}">
<behaviors:Interaction.Behaviors>
<behaviors:BehaviorCollection>
<behaviors:EventToCommand
EventName="Navigating"
Command="{Binding NavigatingCommand}"
PassEventArgument="True" />
</behaviors:BehaviorCollection>
</behaviors:Interaction.Behaviors>
</WebView>
The code in the ViewModel, that matches the tapped url against a list of valid options before opening the link in the device's browser, is:
public Command<WebNavigatingEventArgs> NavigatingCommand
{
get
{
return navigatingCommand ?? (navigatingCommand = new Command<WebNavigatingEventArgs>(
(param) =>
{
if (param != null && -1 < Array.IndexOf(_uris, param.Url))
{
Device.OpenUri(new Uri(param.Url));
param.Cancel = true;
}
},
(param) => true
));
}
}
You canĀ“t navigate with a WebView, you must use a custom render (hybridwebview).
Here is an explanation:
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/hybridwebview/
in a window i have 2 buttons- edit and view.
Now unless a user presses the 'edit' button, i intend that the 'view' button must remain disabled.
Once he presses the edit button, the 'view' button must become enabled and the 'edit' button must become disabled.
also when either of them are enabled ,then on clicking there must be a redirection. Also this state must persist(i.e the 'view' button enabled and 'edit' disabled) when i get back to the same page after redirection or redirected to the same page.
I tried the following but am getting the error: "Event listeners not support native content"
Could someone please help me out.
<button id = "ViewBtn" width="80px" label="View"
disabled="true">
<attribute name="onClick">
<zscript>
<![CDATA[
Executions.sendRedirect("View.zul");
]]>
</zscript>
</attribute>
</button>
</row>
<row>
<button id = "EditBtn" width="80px" label="Edit"
>
<attribute name="onClick">
<zscript>
<![CDATA[
disabled="true";
ViewBtn.setDisabled("false");
Executions.sendRedirect("Edit.zul");
]]>
</zscript>
</attribute>
</button>
</row>
Thanks.
It is because you place inside of .
The event listener (declared with ) already assumes zscript (java code), so you don't have to declare it.