I have created the side menu using the RadSideDrawer directive in nativescript and when I try to load child routes in it, except the default load, all subsequent loads show me a blank screen.
This is how I am loading the content.
<ScrollView tkMainContent class="menu-content">
<router-outlet></router-outlet>
</ScrollView>
Navigation Logic:
<StackLayout>
<StackLayout orientation="horizontal" [nsRouterLink]="['./']" class="menu-item"
[nsRouterLinkActiveOptions]="{exact: true}" nsRouterLinkActive="active" horizontalAlignment="left">
<Label text="{{inspectionsIcon}}" class="icon" ></Label>
<Label text="Reports"></Label>
</StackLayout>
<StackLayout orientation="horizontal" [nsRouterLink]="['properties']" class="menu-item" nsRouterLinkActive="active" horizontalAlignment="left">
<Label text="{{propertiesIcon}}" class="icon" ></Label>
<Label text="Properties" ></Label>
</StackLayout>
<StackLayout orientation="horizontal" [nsRouterLink]="['settings']" class="menu-item" nsRouterLinkActive="active" horizontalAlignment="left">
<Label text="{{settingsIcon}}" class="icon" ></Label>
<Label text="Settings"></Label>
</StackLayout>
</StackLayout>
So when the parent route loads I see the content of the default child. When I switch to any other child routes I see a blank screen. Any help in fixing this would be appreciated.
I know that the navigation logic is fine cause it loads fine when i just comment out the RadSideDrawer and use it as a list view
I had the same issue and its due to a circular reference when the RadSideDrawer is in the same component template as the default home router path, in your case [nsRouterLink]="['./']
In my case, when I added console.log to the constructor of my HomeComponent which contained my RadSideDrawer, i saw the constructor fired twice as well as a label which I had inside:
<ScrollView tkMainContent class="menu-content">
Solution (suggested to me by Telerik) is to have the default route point to another "landing page" like [nsRouterLink]="['welcomPage'] and thereby removing the circular reference.
Related
There is nothing wrong with my code as I can see, but this error I have never seen before keeps coming up, and the Entry element (Input Field) doesn't show up in the UI when I run the app. How to get rid of this problem?
<StackLayout>
<Entry
x:Name="InputField"
Text=""
Placeholder="Enter Todo"
TextChanged="HandleTextChanged"
Completed="HandleCompleted"/>
</StackLayout>
<StackLayout x:Name="TodoList">
</StackLayout>
As Jason suggested in the comments, The Content property of the ContentPage can only accept one direct child element. To get around this, you need to use a Layout container, like a StackLayout or a Grid.
Here's the code sample below for your reference:
<ContentPage.Content>
<StackLayout>
<StackLayout>
<Entry
x:Name="InputField"
Text=""
Placeholder="Enter Todo"
TextChanged="HandleTextChanged"
Completed="HandleCompleted"/>
</StackLayout>
<StackLayout x:Name="TodoList">
</StackLayout>
</StackLayout>
</ContentPage.Content>
I've created a Xamarin.Forms app and I'm using a NavigationPage to hold a stack of ContentPages. The navigation makes sense to me, but I'd like to somehow be able to render the ContentPages underneath the top ContentPage. Specifically, I'd like a transparent background on one that lets some of the page underneath be visible. I know that I could use the popup classes, but they just use the underlying dialog architecture which leaves a lot to be desired, especially on Android.
If this cannot be done natively with something like a simple switch that I've missed, is there any way to create my own NavigationPage class that implements the behavior I'm after? What about any tutorials that would walk me through this process?
As microsoft documents says
A Page object represents a ViewController in iOS and a Page in the
Universal Windows Platform. On Android, each page takes up the screen
like an Activity, but Xamarin.Forms pages are not Activity objects.
On the Android platform, the PageRenderer class instantiates a ViewGroup control.
If you want to display multiple pages, Carousel Page can do the job https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/navigation/carousel-page
To use popup, you can download Rg.Plugins.Popup.Here are my sample code.
popuppage:
<pages:PopupPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:pages="http://rotorgames.com"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:animations="clr-namespace:Rg.Plugins.Popup.Animations;assembly=Rg.Plugins.Popup"
x:Class="MyFormsApp.Views.MyPage1">
<StackLayout VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand">
<Label Text="Hello World!" FontSize="Large"/>
</StackLayout>
</pages:PopupPage>
open popup over mainpage:
public MainPage()
{
InitializeComponent();
PopupNavigation.Instance.PushAsync(new MyPage1(), true);
}
result:
edit:
<AbsoluteLayout>
<Frame BackgroundColor="#2196F3" Padding="24" CornerRadius="0">
<Label Text="Welcome to Xamarin.Forms!" HorizontalTextAlignment="Center" TextColor="White" FontSize="36"/>
</Frame>
<ContentView
BackgroundColor="Red" Padding="10,0" AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All"
Opacity="0.5"
x:Name="myContentview">
<StackLayout HeightRequest="400" WidthRequest="400">
<Label Text="This is a popup" VerticalOptions="CenterAndExpand"
HorizontalOptions="CenterAndExpand"/>
</StackLayout>
</ContentView>
</AbsoluteLayout>
I am creating a rounded menu with Xamarin Forms as Below.
The accent color is my Grid. Then I translatex and trnaslatey the buttons.
My issue is that the click button is not raised. I have also tried on the gesture recognizer of my stack panel. Same result.
The part of the code is below:
<Grid BackgroundColor="Accent" Margin="0,0,0,10" VerticalOptions="End" HorizontalOptions="Center">
<StackLayout x:Name="cat" TranslationX="-109" TranslationY="-102"
>
<StackLayout.GestureRecognizers>
<TapGestureRecognizer Tapped="catBtn_Clicked"/>
</StackLayout.GestureRecognizers>
<Button Clicked="catBtn_Clicked" WidthRequest="60"
HeightRequest="60"
FontSize="35"
CornerRadius="30" HorizontalOptions="Center"
BackgroundColor="{StaticResource RedColor}"
TextColor="White"
Text="{ x:Static local:GrialIconsFont.Calendar }"
FontFamily="{ StaticResource IconsFontFamily }">
</Button>
<Label Text="{extensions:Translate Hello}" HorizontalOptions="Center"/>
</StackLayout>
Make sure that your button is placed inside superView's bounds,
If a button is placed outside superView's bounds, the button will not clickable.
You use TranslationX="-109" and TranslationY="-102" will make the button out of the bounds of StackLayout, so it won't response to the click event. You can add backgroundColor to stacklayout to see its bounds.
I would suggest you to add those buttons or labels directly to Grid and use absolute-layout, relative-layout or other layout to fix their positions.
There are also some examples in Github you can refer, such as CircleButtonMenu, Xamarin.Forms-RadialMenu
In Xamarin Forms 4.1, When scroll, scrollview content is covering/overflow the headerview and scrollview content is not shown completely.
Tried with IsClippedToBounds to true.
Created scrollviewrenderer, OnDraw() -> set clip to bound property. But didn't worked.
Example: Here is the XAML design
<Stacklayout>
<HeaderView/>
<ScrollView IsClippedToBounds="true">
<Stacklayout>
<label text="1"/>
........
........
<label text="100"/>
</Stacklayout>
</ScrollView>
</Stacklayout>
I make a custom control as the headerview in your description. And test on Xamarin.forms 4.1, works well.
MyCustomConrol:
<StackLayout Orientation="Horizontal" BackgroundColor="Aqua">
<Label x:Name="Title_label" Text="Title" TextColor="Black" FontSize="25" HorizontalOptions="StartAndExpand" Margin="8,0,4,0"/>
<Button x:Name="btnHello" Text="Hello" HorizontalOptions="EndAndExpand" Margin="4,0,8,0"/>
</StackLayout>
MainPage.xaml
<StackLayout>
<local:MyCustomControl></local:MyCustomControl>
<!--<HeaderView/>-->
<ScrollView IsClippedToBounds="true">
<StackLayout>
<Label Text="1"/>
<Label Text="2"/>
<Label Text="3"/>
……………
…………………
</StackLayout>
</ScrollView>
Result:
You could download from ScrollView/XamarinDemo folder of GitHub for reference.
https://github.com/WendyZang/Test.git
If you want your header to be always visible then rather than placinf your content in Header, it will be better to place your header content first then below that place your listview. Thus, your header remains intact and listview scrolls.
I have used label class for every label in my project. If any other font color like
class="label font-clr-green"
is applied then it not taking green color. So I decided to overwrite the label class in app.css but it's also a failure. I need to know whether label class can be overridden or not.
I checked your Playground Sample and what I could deduce from it is, that the <Label> used in the problem part is not taking the green color as it should be. Well, that's because you are using this <Label> element inside a <StackLayout> having class input-field. It seems like, CSS for .input-field Label is pre-defined.
The solution to your problem, would be to rename this class input-field to something else. That's all it needed. Below is the updated XML part. You can also check my attached Playground demo with the fix.
<Page loaded="pageLoaded" class="page" xmlns="http://www.nativescript.org/tns.xsd">
<ActionBar title="Home" class="action-bar">
</ActionBar>
<ScrollView>
<StackLayout class="form">
<!--this was working fine -->
<Label textWrap="true" text="Play with NativeScript!" class="label font-weight-bold m-b-5 fcg" />
<Label textWrap="true" text="Play with NativeScript!" class="label font-weight-bold m-b-5"
color="green" />
<!-- the problem was here, solution was to rename input-field to input-field-1 -->
<StackLayout class="input-field-1">
<StackLayout class="okay">
<Label text="Active Flag" class="label font-weight-bold m-b-5 fcg" />
</StackLayout>
<Switch checked="true" class="switch fcg"
horizontalAlignment='left' margin="0" />
<StackLayout class="hr-light"></StackLayout>
</StackLayout>
</StackLayout>
</ScrollView>
Working Playground Demo.