.NET MAUI TableView collapses when Entry control receives focus - maui

I have a TableView in which I render form controls for data editing.
However, as soon as the Entry control receives focus, the ViewCell seemingly collapses, leaving only the section title and separator borders visible:
<TableView Intent="Data">
<TableRoot>
<TableSection Title="Details">
<ViewCell>
<Grid ColumnDefinitions="0.5*,0.5*">
<Label Text="Manufacturer" />
<Entry Text="{Binding Manufacturer}" Grid.Column="1" />
</Grid>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>
Initial state:
After tapping the Entry element:
I've tried setting a specific height for the Grid and the Entry control, but I get the same result regardless.
Am I missing something obvious here? 🤔

It's a bug in .NET MAUI: https://github.com/dotnet/maui/issues/10322
I ran into this a while ago and reported it. For now, I have created my own table using a Grid.

You can change The TableView HeightRequest property to a large number such as 700.
This is a temporary workaround until the bug is fixed.
<TableView HeightRequest="700">
<TableRoot>
<TableSection>
<!-- Your code goes here -->
</TableSection>
</TableRoot>
</TableView>
But, in most scenarios, you don't know what the Height is so you could set it dynamically in your code behind.
Page constructor:
public MainPage()
{
InitializeComponent();
// if you want your table height to fit half of the page
Table.HeightRequest = this.Height / 2;
// Rest of logic...
}
Xaml:
<TableView x:Name="Table">
<TableRoot>
<TableSection>
<ViewCell>
<Label Text="Example"/>
</ViewCell>
</TableSection>
</TableRoot>
</TableView>

Related

Pass the VisualState of CollectionView Item VisualElement to its child VisualElements

I am having the following situation:
CollectionView, each item is Border, that contains other controls.
When selected, the VisualState of the Border changes to selected. The child controls however do not have a change in their state.
Is there an easy way to link/pass those VisualStates to all child controls?
(cascade, 2,3,4 and more levels deeper)
Edit: I know how to use Triggers, Setters in Styles and other approaches to change the UI of the application. The question is specifically for changing the VisualState of the nested VisualElements. Cannot find anything anywhere on this matter.
You can try to set state on multiple elements.
Visual states could be attached to and operated on single elements. And it's also possible to create visual states that are attached to a single element, but that set properties on other elements within the same scope. This avoids having to repeat visual states on each element the states operate on.
The following example shows how to set state on multiple objects, from a single visual state group:
<StackLayout>
<Label Text="What is the capital of France?" />
<Entry x:Name="entry"
Placeholder="Enter answer" />
<Button Text="Reveal answer">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Property="Scale"
Value="0.8" />
<Setter TargetName="entry"
Property="Entry.Text"
Value="Paris" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Button>
</StackLayout>
Note: Property paths are unsupported in Setter elements that specify the TargetName property.
You can also try to define custom visual states, for more information, you can check: Define custom visual states .

Xamarin forms; How to access the label from xaml.cs class of a rg.plugins pop up page?

I have a label in my rg.plugins popup page and I want to change the text color of the label when doing an action.
I try to add an id to the label in xaml, but that is not possible. Is there any way to change the label text color from xaml.cs class.
Thanks in advance
Some sample code would help understand what the issues might be. I assume by rg.plugins, you're referring to: https://github.com/rotorgames/Rg.Plugins.Popup so I will answer accordingly.
It looks like it takes standard xaml and displays that in a dialog type popup. Your options for styling should be the same as any other:
Change color directly in xaml. <Label Text="This is some text" TextColor="Blue" />
Change it via a binding. TextColor="{Binding ColorThatIWant}" Where the page's BindingContext has been set to an object that has a public property or binding property of ColorThatIWant. Don't forget to implement INotiftyPropertyChanged if you want forms to react to property changes.
Set the value in code behind. MyLabel.TextColor = UIColor.Blue; where the label has a name value set. <Label x:Name="MyLabel" Text="This is some text" />
Use style dictionaries to set the value. <Label Text="This is some text" Style="{StaticBinding MyLabelStyle}"/> with a style of:
<Style x:Key="MyLabelStyle" TargetType="Label">
<Setter Property="TextColor" Value="Blue" />
</Style>

DropDownButton in pure XAML (almost works)

I'm trying to do a DropDownButton (or ComboButton) in Pure XAML because I want to use the GUI in PowerShell.
I'm aware of wpftoolkit's DropDownButton but it needs custom C#/c++ code to make it work.(and if I could bring it in, the wpftoolkit would be bigger than my project!)
Below I just stacked a Button control on top of a comboBox control. (Ugly, I know but my options are limited from my point of view)
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="580"
MinHeight="580"
MinWidth="700"
Width="700"
Background="lightgray">
<Grid>
<ComboBox
x:Name="CboxWakeUp"
Width="100"
Height="80"
HorizontalAlignment="Right"
Margin="10,10,10,0"
VerticalAlignment="Top"
Background="green"
IsEditable="True"
IsReadOnly="True"
TextBlock.FontSize="16"
>
<ComboBoxItem Content="WakeUp and RDP" IsSelected="True"/>
<ComboBoxItem Content="WakeUp from list"/>
<ComboBoxItem Content="WakeUp and Run"/>
</ComboBox>
<!-- Button is ON TOP of ComboBox -->
<Button
Name="btnWakeUp"
Width="85"
Height="80"
HorizontalAlignment="Right"
Margin="10,10,25,0"
VerticalAlignment="Top"
Background="green"
TextBlock.FontSize="16"
>
<!-- This would makes the SelectedValue text wrap but the binding binding syntax used is taken literally -->
<TextBlock Text="{Binding SelectedValue, ElementName=CboxWakeUp}" TextWrapping="Wrap" TextAlignment="Center"/>
</Button>
</Grid>
</Window>
I'm close but I need help.
I need to wrap the text of the button and I have figured it out by embedding a TextBlock control inside the Button control (Thank you TheMadTechnician! ) but the binding syntax I used in the button is taken literally.
NOTE: I had the binding to the button working directly but when a selection was made in the ComboBox, Kaxaml gave me "Must disconnect specified child from current parent Visual before attaching to new parent Visual" error. I'm hoping the TextBlock control will side-step this issue.
PS: I was going to try to make the button change colour based on the selection made in the ComboBox:
WakeUp and RDP ==> Green
WakeUp from list ==> Blue
WakeUp and Run ==> Red
This will have to be done in PS code and that's ok

FlexBox Item growFactor is not updating the style if the binding is changing

Here is the plunker link: http://plnkr.co/edit/XVINtJ1RbNrkaCAFbZti?p=preview
I have a view with a FlexBox with 2 items that span 100% width.
<FlexBox width="100%">
<items>
<Button press="onButtonLeftPress" text="{LayoutModel>/left}" width="100%" type="Emphasized" >
<layoutData>
<FlexItemData growFactor="{LayoutModel>/left}" />
</layoutData>
</Button>
<Button press="onButtonRightPress" text="{LayoutModel>/right}" width="100%" type="Reject">
<layoutData>
<FlexItemData growFactor="{LayoutModel>/right}" />
</layoutData>
</Button>
</items>
</FlexBox>
The growFactor of the 2 FlexBox items are bound to a LayoutModel that is initialized in index.html
var layoutModel = new sap.ui.model.json.JSONModel();
layoutModel.setData({
left: 2,
right: 1
});
ui5Core.setModel(layoutModel, "LayoutModel");
By pressing the buttons I update the model properties "left" and "right". The values are updated as you can see but the style for the items is not updated.
I see that FlexBox is taking into consideration only at initialization the values, but if the value is changed the UI is not updated.
The main idea is that I'm trying to obtain a layout with 2-3 columns that collapse/expand.
Do you have any ideas how to obtain this? or how to solve this FlexBox bug?
Many thanks
You have to call invalidate() on the FlexBox instance inside your handler functions. This will make the FlexBox rerender and everything works as expected. Here is a "One-File" jsbin example: https://jsbin.com/pisadigene/edit?html,output
I did not check the code of the FlexBox but I guess that updating the GrowFactor of a FlexBox item does not trigger a change (i.e. rerendering). I guess it’s just a one-time thing...
However, you should be aware that using invalidate() will trigger a re-rendering for all content inside the FlexBox. So that is not a good idea in case you have a lot of content inside the FlexBox because it can have a negative effect on performance… I am not very sure what you try to achieve but using flexboxes for a complete layout of the app might not be a good idea. Instead you should check the other opportunities you have with SAPUI5, i.e. MatrixLayout etc.

Itemscontrol to position items horizontally and make children stretch to stackpanel width

I'm creating a grid like control, and i'm using an itemscontrol to represent a row and the another itemscontrol to put those rows together. In a row, the items are positioned horizontally so I use a StackPanel with a horizontal orientation like this:
<ItemsControl ItemsSource="{Binding CellRows}" Grid.Row="1" Grid.Column="1" Margin ="20">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" Background="Cyan"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBox Text="{Binding Content}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
By default, I want my StackPanel to take the size its parent has and that happens. But I also want all the children in the itemscontrol (with the stackpanel as itemspanel) to take up the full width of its parent. But that doesn't happen.
I've read that is default behavior of a stackpanel as well.
My questions:
1) Is there any way to make my textboxes (children) to take up the full width of my stackpanel (parent)? I don't know how many items the stackpanel will contain, so I can't give a default width to the textboxes.
2) Is there any other to represent 2D data? (I'm working with silverlight 4 MVVM)
Thanks in advance.
Check out the UniformGrid for SL control here: http://www.jeff.wilcox.name/2009/01/uniform-grid/
The definition of the UniformGrid from the MSDN: "Provides a way to arrange content in a grid where all the cells in the grid have the same size."
If you want this to be bound to an observable collection simply place the UniformGrid in the ItemsPanelTemplate of an ItemsControl as UniformGrid extends Panel.