How to limit the width of a Button in NativeScript? - css

I'm using NativeScript-Vue to build some app. Trying to figure out how to control the size of my buttons. For instance, i have this code:
<StackLayout orientation="horizontal">
<Button
class="fas"
:text="'fa-upload' | fonticon"
#tap="()=>{backupImage(image)}"
></Button>
<Button
v-if="image.taskStatus==='pending'"
class="far"
:text="'fa-window-close' | fonticon"
#tap="()=>{cancelImageBackup(image)}"
></Button>
</StackLayout>
The result is this:
I would like to remove the large "empty" gray area, on both sides of the icon. I see that native script doesn't support max-width. Tried also padding. How can it be done?

For some reason, works with a StackLayout around it
<StackLayout>
<Button text="LOGIN" class="-rounded-sm bg-primary" width="100dip"></Button>
</StackLayout>

Related

Add icons to a TextField NativeScript

How to add icons to a TextField with NativeScript like you can see on the image: here
My xhtml code:
<StackLayout>
<Image src="res://logo_login" stretch="none" horizontalAlignment="center"></Image>
<TextField #username class="input" hint="GEBRUIKERSNAAM" [(ngModel)]="user.username" autocorrect="false"
autocapitalizationType="none"></TextField>
<TextField #password class="input" hint="PASWOORD" secure="true" [(ngModel)]="user.password"></TextField>
<Button class="btn btn-primary btn-login icon" text="\e912 INLOGGEN" (tap)="login()"></Button>
<button class="btn btn-forgot-pass" text="PASWOORD VERGETEN?" (tap)="forgotpass()"></button>
Check out icon fonts for NativeScript:
https://docs.nativescript.org/ui/icon-fonts
"...
Follow the instructions on the icon font webpage to determine the hex codes of each font glyph, i.e., icon. Add a Label component to your NativeScript app and bind the Label's text property to a one-letter string generated from the character code of the icon you want to show, i.e., String.fromCharCode(0xe903).
..."
I believe this is what you're trying to do.
You can wrap your TextFields in a StackLayout with a horizontal orientation like
<StackLayout orientation="horizontal">
<!--Your password TextField-->
<TextField
#password
class="input"
hint="PASWOORD"
secure="true"
[(ngModel)]="user.password"
></TextField>
<!--You can then place the icon-->
<Label class="fa" text="" (tap)="toggleShow()"></Label>
</StackLayout>

Xamarin.Forms View-to-View binding without changing BindingContext

I have a Button defined in XAML that contains a Command including a CommandParameter. The Command binds to the current view's ViewModel, while the CommandParameter binds to another control within the current view. In WPF this would look like:
<TextBox x:Name="MyTextBox" />
<Button Command="{Binding ViewmodelCommand}"
CommandParameter="{Binding ElementName=MyTextBox, Path=Text}" />
According to documentation, in Xamarin.Forms View-to-View binding is possible via changing a control's BindingContext using the x:Reference markup extension:
<Button BindingContext="{x:Reference Name=MyTextBox}"
CommandParameter="{Binding Path=Text}" />
In this case, however, I'm not able to bind the Command to the global Viewmodel! Are there any solutions to this scenario?
Try this:
<Button Command="{Binding ViewmodelCommand}"
CommandParameter="{Binding Source={x:Reference MyTextBox}, Path=Text}" />
Did you solve this?
what I did was to add a binding MyTextBox <-> viewModel like:
MyTextBox.SetBinding(Entry.TextProperty, "PropName");
btn.SetBinding(Button.CommandProperty, "CommandName");
btn.SetBinding(Button.CommandParameterProperty, "PropName");

How to do padding on a textarea (titanium)

This works fine with a text field:
<TextField id="txtNick" paddingLeft='15' top='10' maxLength='20' width = '300' />
However the following code does not work in a text area:
<TextArea id="txtAbout" maxLength='250' paddingRight='10' top='10' width = '300' borderStyle="Ti.UI.INPUT_BORDERSTYLE_ROUNDED"/>
Any idea how to achieve padding? Cheers
You can't with single TextArea. but you can:
<View height="Ti.UI.SIZE">
<TextArea left="10 right="10" />
</View>

WPF UnifromGrid:How to style selected Child with rounded corners like in Explorer

This is a link for a question asked before, which concerns a TreeView:
WPF TreeView: How to style selected items with rounded corners like in Explorer
And this is another link for another question asked too, which concerns a ListView:
WPF ListView: How to style selected items with rounded corners like in Explorer
My question is : How to migrate this Solution on a UniformGrid ? Because I want to have the same effect as shown in the 2 examples, on my UniformGrid Cells.
here is an example of my source code:
<Grid VerticalAlignment="Center" HorizontalAlignment="Center" >
<ItemsControl ItemsSource="{Binding ChildrenList}" BorderThickness="0"
HorizontalContentAlignment="Center" VerticalContentAlignment="Center" >
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding NumberOfColumns}" HorizontalAlignment=
"Center" Background="Transparent" Margin="4,4,4,4" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
</ItemsControl>
</Grid>
You're half-way there already :)
You need to use a ListBox instead of an ItemsControl (because ItemsControl doesn't handle selection and has no such thing as a "selected item").
Then you use the same ItemsPanel as in your example, and the same ItemContainerStyle as in the ListView post you linked to (note: just make sure you rename stuff from "ItemsControl"/"ListView" and "ListViewItem" to "ListBox" and "ListBoxItem"):
<ListBox ItemsSource="{Binding ChildrenList}" >
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="{Binding NumberOfColumns}" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<!-- NOTE: "ListBox" and "ListBoxItem": -->
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
...
</Style>
</ListBox.ItemContainerStyle>
</ListBox>

ZK: enable button in listcell only for the selected item of a listbox

In the next listbox I load elements with template:
<listbox model="#load(vm.resAccepted)" selectedItem="#bind(vm.selResAccepted)">
<template name="model">
<listitem>
<listcell label="#load(each.eventName)" />
<listcell label="#load(each.userName)" />
<listcell>
<button image="/img/button_mail.png"/>
</listcell>
</listitem>
</template>
</listbox>
My goal is to enable the button of the listitem ONLY for the row the user selects.
To do this, I try
<button disabled="#load(vm.selResAccepted.id=each.id?'false':'true')" />
checking if the unique field id is the same of the selected element, but it fails.
Any help will be appreciated.
You can use eq for equals comparison:
<button disabled="#load(vm.selResAccepted.id eq each.id?'false':'true')" />
or maybe even better: disabled when selected item is not the current item
<button disabled="#load(vm.selResAccepted ne each)" />
here ne is not equal

Resources