Smallest possible Label inside a Grid with line breaks - maui

I have a Label inside a Grid. I want:
The Grid and the Label to be as small as possible.
The Label should use up to two lines if necessary.
This is what I have:
<VerticalStackLayout Spacing="8">
<Label Text='With HorizontalOptions="Start":' />
<Grid BackgroundColor="#FCC" HorizontalOptions="Start">
<Label
Text="This will not wrap."
MaxLines="2"
/>
</Grid>
<Grid BackgroundColor="#FCC" HorizontalOptions="Start">
<Label
Text="This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. This will not wrap. "
MaxLines="2"
/>
</Grid>
<Label Text='With HorizontalOptions="Fill":' />
<Grid BackgroundColor="#CFC" HorizontalOptions="Fill">
<Label
Text="This wraps, but fills."
MaxLines="2"
/>
</Grid>
<Grid BackgroundColor="#CFC" HorizontalOptions="Fill">
<Label
Text="This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills. This wraps, but fills."
MaxLines="2"
/>
</Grid>
</VerticalStackLayout>
And this is how it looks:

In conclusion, this is a known issue that be tracked in this thread:https://github.com/dotnet/maui/issues/10494. As #Shaw suggested, we can replace the Grid with an StackLayout to fix the issue. I'll keep an eye on the thread until this is being totally solved.
Thanks for your feedback and patience!

Related

Form: make fields in the same row have the same length

In this sap.ui.layout.form.SimpleForm, I have 2 controls in the same row. Right now, they're somewhat uneven without any formatting done to them. How do I make these 2 controls both occupy 50% of the total row space?
I think this can be seen in the following sample:
https://sapui5.hana.ondemand.com/#/entity/sap.ui.layout.form.SimpleForm/sample/sap.ui.layout.sample.SimpleFormToolbar
Basically all controls have the aggregation <layoutData>. There you can add your own layout information:
<Input value="{ZIPCode}">
<layoutData>
<l:GridData span="XL2 L1 M3 S4" />
</layoutData>
</Input>
Of course this also works for a Select.
Now you just have to determine what you want to pass to the span property:
Usually layouts are based on a 12 column grid. You have to assign some columns to your Labels, maybe some empty space at the end and the rest belongs to your Inputs or Selects.
Your SimpleForm will probably have these properties:
<f:SimpleForm layout="ResponsiveGridLayout"
labelSpanXL="4"
labelSpanL="4"
labelSpanM="4"
labelSpanS="12"
emptySpanXL="0"
emptySpanL="4"
emptySpanM="0"
emptySpanS="0">
So for XL you see that 4 columns already belong to the Label and 0 to empty space at the end so you have 8 columns left. Therefore both form controls should get 4 columns.
L has 4 Label columns and 4 empty columns so each form control should get 2 columns.
M is similar to XL.
S already has 12 columns for the Label. Therefore your controls will be pushed into a second row below the Label where they each can use 6 columns.
So in that example I would suggest passing the following layoutData to both controls so they take equal space. If your SimpleForm has different values for label space end empty space then you have to recalculate.
<l:GridData span="XL4 L2 M4 S6" />
Remember to declare the l namespace at the beginning of your View so you can use the GridData control:
<mvc:View
...
...
xmlns:l="sap.ui.layout">

xamarin form: Can the control bind itself?

Let say I have an Image tag inside the xaml and wanted to be in square size.
<Grid HorizontalOptions="Fill">
<Grid.RowDefinitions>
<RowDefinition Height="auto">
</RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image></Image>
<Image></Image>
<Image></Image>
<Image></Image>
</Grid>
A demo code here have 4 image putting them horizontally within the Grid. The width will be equally defined. So I want the height to be the same as the width. Can I bind themselves like this
<Image x:Name="img" BindingContext="{x:Reference img}" WidthRequest="{Binding HeightRequest}" Grid.Column="1" Grid.Row="0">
Unless you specifically set it somewhere else in code, your WidthRequest will be -1, indicating the control does not explicitly state what width it would like to have, but instead relies on the layout system to workout the correct dimensions.
So this binding, while technically correct, will be useless.
You can try binding to the Width property, which is the readonly property which gets updated with the actual dimensions once the control is laid out.
You can also override the appropriate event and assign the required height there.
Keep in mind that a grid row with height="Auto" will cause A LOT of layout calculation to be done. Especially when changing control sizes after they are already in the visual tree.
Your layout runs **will be* slow.
I suggest you work out a better solution. Such as applying a fixed height to the grid row once the layout engine works out what the cell width for that device is.

Can we remove a Block (West, East, North or South block) out of a DockLayoutPanel?

I like DockLayoutPanel cos it's quite solid. However, there's a big problem.
That is how to remove a Block (West, East, North or South block) out of a DockLayoutPanel?
Let say, i got this code
<g:DockLayoutPanel ui:field="centralDockLayoutPanel">
<g:center>
<g:LayoutPanel ui:field="mainPanel"/>
</g:center>
<g:east size="200">
<g:HTMLPanel ui:field="happyHTMLPanel" width="100%" height="100%">
Some more widgets here
</g:HTMLPanel>
</g:east>
</g:DockLayoutPanel>
I want to remove the East block out of the centralDockLayoutPanel. So i tried
getView().getCentralDockLayoutPanel().remove(getView().getHappyHTMLPanel());
But that doesn't work
getView().getHappyHTMLPanel().setVisible(false);
also doesn't work
Can we remove a Block (West, East, North or South block) out of a DockLayoutPanel?
You could try to do :
getView().getCentralDockLayoutPanel().remove(getView().getHappyHTMLPanel());
getView().getCentralDockLayoutPanel().forceLayout();
Or you can hide your panel:
getView().getCentralDockLayoutPanel().setWidgetHidden(getView().getHappyHTMLPanel(), true);
getView().getCentralDockLayoutPanel().forceLayout();
I always make their size between zero and non-zero, representing hidden and display respectively. By that, you can even add some animations when changing the size of the children.

avoid inertia scrollviewer for negative offset Windows 8 App

i would like to know how can i remove the inertia effect of the scrollviewer content when the offset is negative.
In reality the offset is 0.0, but the content moves in negative like a spring.
This is a video that show the effect that i'd like to remove:
http://www.youtube.com/watch?v=3kXce-VK--4&feature=youtu.be
The code is very simple:
<ScrollViewer x:Name="CalendarScrollViewer"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Auto"
Grid.Column="2" Grid.Row="1"
ZoomMode="Disabled"
HorizontalAlignment="Right"
LayoutUpdated="CalendarScrollViewer_LayoutUpdated" >
<Grid>
...
</Grid>
</ScrollViewer>
Thanks.
Have you tried to set ScrollViewer.IsScrollInertiaEnabled="False" ?

Legend in slice of Pie chart in silverlight

I have pie chart developped in VS using silverlight.
I have a legend with the colors of each slice.
However, I want to show above each pie slice, the legend and it's value. It's possible to do this?
<chartingToolkit:Chart
x:Name="PieChart"
Margin="50,0,44,0"
Grid.Row="7"
Title="{Binding SelectedGraphOptions, Mode=OneWay}"
VerticalAlignment="Top" Height="478"
Visibility="{Binding PieChartVisibility}">
<chartingToolkit:PieSeries
ItemsSource="{Binding Data}"
IndependentValueBinding="{Binding XAxis}"
DependentValueBinding="{Binding YAxis}" />
</chartingToolkit:Chart>