In Xamarin Forms, I want to create a 2-column table where the first column expands to the width of the cell with the longest content, like:
What's the best way to accomplish this in Xamarin.Forms?
Make the first column 'auto' and the second '*'. According to the docs auto should be the size of its children and * will take the remaining space.
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
Related
I am forced to use multiline={false} and set the height of TextInput in order to show it like it is a text area. Reason is that multiline={true} doesn't work very well with KeyboardAvoidingView (https://github.com/facebook/react-native/issues/16826).
So here is a simple code:
<TextInput placeholder="Input text here..." style={{height: 200}} multiline={false} />
and the output is: Screenshot
I just want to make it the text align at the top. Works properly with Android though
Set style property textAlignVertical to top on the TextInput
<TextInput ... multiline={true} textAlignVertical: 'top' />
I have problems to set the width of my XUL button. I have this code:
<button label="Ok" width="16" maxwidth="16" height="16" maxheight="16"/>
By with that code, the size of my entire window is changed and not only the button.
And when I write that :
<button label="Ok" width="16" height="16"/>
Only the height is changed. Why is that?
XUL uses the flexible box model for positioning. The width and height attributes define the intrinsic size of the element, not the size at which they are displayed. Your button is apparently placed in a vertical box (not necessarily the actual vbox element, rather any element with orient="vertical"). By default, the align attribute of a box is assumed to have the value stretch - so a vertical box will always stretch the elements inside it horizontally:
<vbox>
<!-- this button is stretched horizontally to match the width of its container -->
<button label="Ok" width="16" height="16"/>
</vbox>
You can set the align attribute explicitly to avoid this:
<vbox align="center">
<!-- this button is centered inside its container -->
<button label="Ok" width="16" height="16"/>
</vbox>
In iOS is there a UIView to lay out two child views in a column (or row) such that one view has a fixed height (or width) and the other view expands to fill the empty space?
WPF has the System.Windows.Controls.Grid class, for example. I would use it to solve this problem as follows:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="123" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="I have a fixed height" />
<Label Grid.Row="1" Content="My height expands to fill the empty space" />
</Grid>
I have stackPanel created in design (xmal) which has Auto height and width. Adding list of image controls dynamically in Code on Load to stackPanel. Now it works fine. But when i try to resize the window, though the stack panel gets resized due to auto, but not the image contrl.
How to bind the actualheight of stackpanel dynamically to image control height, (so when ever stakpanl height gets changed ,image control also should get changed !!).
thanks
Use a ViewBox
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Viewbox MaxWidth="500" MaxHeight="500" Name="vb1">
<Image Source="tulip_farm.jpg"/>
</Viewbox>
</StackPanel>
How to: Apply Stretch Properties to the Contents of a Viewbox
Or you could use binding as below:
<StackPanel x:Name="MyStackPanel">
<Image Source="C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg" Stretch="Uniform" Height="{Binding ElementName=MyStackPanel, Path=ActualHeight}"></Image>
</StackPanel>
Here's my xaml
<Button x:Name="btnTest" Width="88" Content="{Binding Value, ElementName=slSlider}" Height="{Binding Value, ElementName=slSlider}" HorizontalAlignment="Left" ></Button>
<Slider x:Name="slSlider" SmallChange="1" LargeChange="10" Maximum="100" Height="32" VerticalAlignment="Top" UseLayoutRounding="False" d:LayoutRounding="Auto" HorizontalAlignment="Left" Width="256" ></Slider>
Very simple stuff. Now what I want to do is restrict the button to only grow in an upwards direction, instead of growing both upwards and downwards. How's this done?
Thanks
Set a MinWidth or MinHeight. There's also MaxWidth and MaxHeight if you need them.
Although re-reading your question I am unsure if you're asking about limiting the minimum size of the button or if you actually are talking about alignment. If you're talking about alignment and you want the top of the button to grow out while the bottom stays in position, set the VerticalAlignment of the Button to "Bottom".