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

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>

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 .

.NET MAUI TableView collapses when Entry control receives focus

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>

What is the Property for "Text inside label" in SAPUI5

Suppose my text is "Hello have a nice day", so I want only nice text is in label
<Text text="Hello have a "><Label text="nice"></Label>"day"</Text>
textis property of Label control, not an aggregation.
To set text of Label you can simply do:
<Label text="Hello World" />
The sap.m.Label control has in fact a text property, so you define the text as
<Label text="Label text" />
Similarly the sap.m.Text control has a text property, so you define the text as
<Text text="Text text" />
However the Text control does not have an aggregation for other Controls, so you cannot nest a Label inside a Text.

How to append a link to gwtbootstrap 3 InputField

I want to do this in html:
<div class="input-group" id="name">
<input type="text" class="form-control" name="name" placeholder="Name">
<span class="input-group-addon">None</span>
</div>
I try this in GWT Bootstrap:
<b:InputGroup>
<b:TextBox b:id="name" placeholder="Name"/>
<b:InputGroupAddon>
<b:Anchor ui:field="noName" text="None"/>
</b:InputGroupAddon>
</b:InputGroup>
But thus I get the error:
Illegal child <b:Anchor text='Name' ui:field='noName'> in a text-only context. Perhaps you are trying to use unescaped HTML where text is required, as in a HasText widget?: <b:InputGroupAddon> (:56)
Why? b:Anchor implements HasText interface.
My aim is to add a link on which, when a user clicks input will fill value NONE
The HasText bit is about InputGroupAddon, not Anchor. "Text-only context" (implied by implementing HasText) means you can only put, well, text into that widget. Either through the text property (<b:InputGroupAddon text='Name' />) or inside the tags (<b:InputGroupAddon>Name</b:InputGroupAddon>) - those declarations are equivalent. You can't put unescaped HTML or widgets in such a context.
For your use case, I'd recommend using buttons (as the Bootstrap docs suggest):
<b:InputGroup>
<b:TextBox b:id="name" placeholder="Name" />
<b:InputGroupButton>
<b:Button ui:field="noName" text="None" />
</b:InputGroupButton>
</b:InputGroup>
See the demo to see it in action. You can easily style it to your needs (maybe no text and just an icon = "ERASER").

How can I set text value dynamically in SAPUI5?

I want to set a text value by taking a value from another page or another input area. Here is my text field. I tried many combinations for this.byId("thisOne")., but they didn't work.
this.byId("thisOne").setValue("Some thing");
another way:
sap.ui.getCore().byId("thisOne")....
The text element:
<Text text="" id ="thisOne"/>
My XML file:
<mvc:View
xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m" controllerName="App.view.Take"
xmlns:l="sap.ui.layout"
xmlns:f="sap.ui.layout.form">
<Page showHeader="false">
<Label text="thisOne" />
<Input text="" id="thisOne" />
<Button type="Accept" text="Accept" ></Button>
<Button type="Reject" text="Reject" ></Button>
</Page>
</mvc:View>
If you specify an ID explicitly for a control, within an XML view, the actual ID will be prepended with the ID of the XML view, for example the Input control might have an actual ID of "__xmlview0--thisOne".
Best practice is to use the XML View's byId function to get the ID of a control contained within it. So for example in your controller attached to the view (App.view.Take.controller.js in your case) you could do this:
this.getView().byId("thisOne").setValue("Some thing");
Note that setValue will NOT work.
setValue is not the supported method for sap.m.Text Control. setValue is supported for sap.m.Input (or any other control which inherit properties from sap.m.Inputbase )
var oValue = sap.ui.getCore().byId("inputId").getValue();
Then
sap.ui.getCore().byId("thisOne").setText(oValue);
Refer to sap.m.Text and sap.m.Input for more details.
If you want to get your textfield and then add a value to it. You have to do this:
sap.ui.getCore().byId("thisOne").setValue("Some thing");