Is there a way to display a details view in .NET MAUI, like you do with the <details> tag in html? - view

Hello I am trying to display data on labels and I want to provide extra details about the data, when the user clicks on a button e.g. .
I know there is the tag in html, where you can define a summary and the details below.
Is there a way, or even better a ContentView, which can do that in .NET MAUI?
I've thought about adding a temporary label under the summary label, with the details, but that looks weird and is not intuitive.

If by details you mean a collapse / expander (which seem to be what details is in html) you can use the expander from the .net maui community toolkit :
<Expander>
<Expander.Header>
<Label Text="Baboon"
FontAttributes="Bold"
FontSize="Medium" />
</Expander.Header>
<HorizontalStackLayout Padding="10">
<Image Source="http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg"
Aspect="AspectFill"
HeightRequest="120"
WidthRequest="120" />
<Label Text="Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae."
FontAttributes="Italic" />
</HorizontalStackLayout>
</Expander>
Otherwise if you just want to provide some additional texte about an element I would go with tooltips.
<Button Text="Save"
ToolTipProperties.Text="Click to Save your data" />

Related

Change ToolbarItem Text/Icon parameters

I am new to MAUI. And I haven't done anything complex with Xamarin as well.
The application I am testing with, has Shell navigation. And I can't find a way to change the toolbar items.
I would like to be able to change either the FontSize of the text, or the color of the SVG image. And I do not want those changes to affect the rest of my application, if possible. But if there is no other way, I can live with it.
I have managed to add styling to buttons, Labels etc... If styling is an option to this, it will be even better.
If I am on the wrong path, if you point me out why, I will be also grateful.
Thank you in advance!
If you want to just change a part of pages in your project. You can try to use a <Shell.TitleView> instead of the <Shell.ToolBarItem> in the content pages you want. Such as:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiAppTest.MainPage">
<Shell.TitleView>
<HorizontalStackLayout Margin="5" HorizontalOptions="End">
<Label Text="hello" TextColor="Red" FontSize="Medium" VerticalOptions="Center" HorizontalOptions="End" />
<Image Source="your image" Margin="10" Background="green"/>
</HorizontalStackLayout>
</Shell.TitleView>
You can change style of TabBar in Style.xaml in path \Resources\Style\. Search in file for Shell.TabBarForegroundColor. You will get TargetType="Shell" and this is style for AppShell.xaml.

Can Nativescript 4.0 new Frame use more elements than Tabview or Sidedrawer?

I see that Frame works now much better.
We can have Tabview,that is a root of current view.
<TabView androidTabsPosition="bottom">
<TabViewItem title="First">
<Frame defaultPage="home/home-page" />
</TabViewItem>
<TabViewItem title="Second">
<Frame defaultPage="second/second-page" />
</TabViewItem>
</TabView>
This looks like home-page or second-page is “included”.
Now, i’m wondering if it’s possible to have app-root.xml that holds common elements, and needed page is included. I’ve tried this, but this is not working (why? This approach is possible only for tabview and sidedrawer ?)
app-root.xml
<Page>
<Frame defaultPage="create/create"></Frame>
</Page>
create/create.xml
<StackLayout class="footer white">
<Label text="test"></Label>
</StackLayout>
Instead of Page use layout like GridLayout Look at this test application as a reference and more specifically this page
However, the above approach would work for Android but for iOS, you should either remove the action bar for each Page (inside each Frame) or create multiple action bars (not recommended!).

Nativescript tab layout approach

I am trying to create an app with NativeScript with the following layout:
On top, action bar
Content Area in the center (about 80% of screen height)
Fixed menu on bottom with 4 buttons
I know that NativeScript provides a TabView, however this view puts the menu on top for the android version of the app,and doesn't allow to use images as "ItemTitle".
So (I think) this leaves me with two options :
Create 4 different pages and load them when a user taps on the menu
buttons
Create one single page and change content according to user
selection
The first approach is great because I get to separate all xml , js and css files. However navigating between pages can take some time and doesn't give ideal user experience.
The second approach probably will have a better user experience but code will be very hard to maintain.
Which option should I use? Have any of you dealt with a similar layout?
Thank you for your time!
In my app I use the TabView with partial-views in each tab-item. So for each tab-view the content is separated in their own xml,js,css files.
So why not just take this approach and combine it with your option 2?
You could create a main-view with:
ActionBar
Centered main-content for partial-views (Stack- og GridLayout)
SegmentedBar at the bottom for navigation buttons
When the user taps a button on the SegmentedBar, you change the visibility of the corresponding partial-view.
You can use any font-icons as "images" for your title in the SegmentedBar also.
UPDATE: Added examples below.
How to create and reference partial-views
In your main-view Page-element add the references to each partial view, like here:
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded"
xmlns:t1="partial-views/tab1"
xmlns:t2="partial-views/tab2"
xmlns:t3="partial-views/tab3">
Each partial view consists of a .xml, .js and perhaps a .css file. I like to place each partial view in separate folders: tab1, tab2, tab3 as an example.
The partial-view xml file would contain only the view-modules, no page-modules. So don't add any Page or ActionBar here. Example of a partial view .xml:
<GridLayout loaded="viewLoaded">
<ListView items="{{ someItemList }}">
<ListView.itemTemplate>
...
</ListView.itemTemplate>
</ListView>
</GridLayout>
How to use partial-views
Now, it's up to you how you want to use the partial-views. Here is an example on how to use them together with a TabView component. This is placed in the same page-view where you added the references from the first example.
<TabView>
<TabView.items>
<TabViewItem title="Tab 1" iconSource="res://tab1">
<TabViewItem.view>
<t1:tab1 />
</TabViewItem.view>
</TabViewItem>
<TabViewItem title="Tab 2" iconSource="res://tab2" >
<TabViewItem.view>
<t2:tab2 />
</TabViewItem.view>
</TabViewItem>
<TabViewItem title="Tab 3" iconSource="res://tab3" >
<TabViewItem.view>
<t3:tab3 />
</TabViewItem.view>
</TabViewItem>
</TabView.items>
</TabView>
Or, you could do it without the TabView, and create something custom:
<StackLayout>
<t1:tab1 id="tab1" visibility="visible" />
<t2:tab2 id="tab2" visibility="collapsed" />
<t3:tab3 id="tab3" visibility="collapsed" />
</StackLayout>
<SegmentedBar selectedIndex="0" selectedIndexChanged="segBarSelected">
<SegmentedBar.items>
<SegmentedBarItem title="Tab 1" />
<SegmentedBarItem title="Tab 2" />
<SegmentedBarItem title="Tab 3" />
</SegmentedBar.items>
</SegmentedBar>
So here would selectedIndexChangedcontrol the visibility of each partial view.

TabView vs SegmentedBar

I am creating SegmentedBar in native script. I am able to create segments but I am not able to add Label to segment view.
<Page xmlns="http://www.nativescript.org/tns.xsd" loaded="pageLoaded">
<StackLayout>
<SegmentedBar>
<SegmentedBar.items>
<SegmentedBarItem title="Segment 1">
<SegmentedBarItem.view>
<Label text=" I am in segment bar 1"/>
</SegmentedBarItem.view>
</SegmentedBarItem>
<SegmentedBarItem title="Segment 2">
<SegmentedBarItem.view>
<Label text=" I am in segment bar 2"/>
</SegmentedBarItem.view>
</SegmentedBarItem>
</SegmentedBar.items>
</SegmentedBar>
</StackLayout>
</Page>
What is the difference between SegmentedBar and TabView as both appear same.
The Segmented bar is described in a good way by Apple:
A segmented control is a horizontal control made of multiple segments,
each segment functioning as a discrete button.
So basically: A Segmented Bar is a couple of buttons (visually) connected to each other. Just think of them like buttons with a specific look.
A TabView on the other hand the tabs (the items you click) and a connected view to each tab.
What you're doing in your code is that you're trying to combine mechanics of the TabView with the SegmentedBar.
Take a look at these two code examples.
First, the SegmentedBar. Here is an example. When you click the "First", "Second" or "Third" button nothing will happen. To react on a button press you've to bind the selectedIndex to an Observable object property and do your logic in the on the propertyChange event.
<SegmentedBar selectedIndex="{{ selectedIndex }}">
<SegmentedBar.items>
<SegmentedBarItem title="First" />
<SegmentedBarItem title="Second" />
<SegmentedBarItem title="Third" />
</SegmentedBar.items>
</SegmentedBar>
The TabView, on the other hand, consist of two things, the tabs themselves (the things you press) and a View connected to each tab. So when you click a tab the view gets changed.
<TabView>
<TabView.items>
<TabViewItem title="Tab 1">
<TabViewItem.view>
<Label text="Label in Tab1" />
</TabViewItem.view>
</TabViewItem>
<TabViewItem title="Tab 2">
<TabViewItem.view>
<Label text="Label in Tab2" />
</TabViewItem.view>
</TabViewItem>
</TabView.items>
</TabView>
These two components are used for different things. E.g. for filtering a list (show all mails, show only unread mails...) you usually use the segmented bar as you don't want to change the view - you want to change the content of the view. The TabView is used for when you actually want to display a whole new view.
You may know the <TabView> is created keeping in mind to show different pages/views in single page/view. Thus, TabView is used mainly for navigating to different views.
The SegmentedBar is created for different purpose. This can be used in a view with different functionality for example you can categorize the contents/products as Free, Paid. You would want to show different product features, services on Free view and Paid view. Thus, you can use the SegmentedBar to show different options for the user.
So, now you know the difference between the TabView and the SegmentedBar.
The correct use of SegmentedBar is to use like this:
<SegmentedBar>
<SegmentedBar.items>
<SegmentedBarItem title="Free" />
<SegmentedBarItem title="Paid" />
</SegmentedBar.items>
</SegmentedBar>
To conclude, use TabView for navigating multiple pages in single page and use SegmentedBar for viewing different content in a single view.

Removing underline from hyperlink in Windows Store app

I'm creating a universal Windows Runtime App for Windows Phone 8.1 and Windows 8.1 using Xaml and C#.
I have inline hyperlinks setup as so -
<TextBlock Width="400" TextWrapping="Wrap">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com">bing</Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
This will display the text with a underline indicating the clickable hyperlink. However I want to indicate hyperlinks by color not underline as I can have multiple of them in a TextBlock.
I want to remove the underline from the inline Hyperlinks - TextDecorations property no longer exists in WP 8.1 and Windows 8.1 Store apps.
Note* I'm using Hyperlink element not HyperlinkButton as I need to have the links inline with text.
I would write a comment, but my reputation is not enough to do that.
I tried the same code on a blank both win 8.1 and win phone 8.1 project. However, the hyperlink is displayed with color by default, not with an underline as opposed to your project. My code is like below
<TextBlock Width="400" TextWrapping="Wrap">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com" Foreground="#FF0007FF">bing</Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
Could you try the Foreground property? Maybe it helps you.
In the final version of Windows 8.1 the Hyperlink-element doesn't have an underline. Maybe the confusion was caused by the focus border around the hyperlink? So the XAML:
<TextBlock Width="400" TextWrapping="Wrap" VerticalAlignment="Center">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com">bing</Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
Shows as:
One thing that can trick the viewer is that if the page doesn't have any other focusable items, the Hyperlink gets the focus and a border is drawn around it. This may look like it has underline:
If you want to get rid of that, add Button with Opacity 0 to the top of the page.
If you want to style the Hyperlink, you can overwrite it using the following keys:
<SolidColorBrush x:Key="HyperlinkDisabledThemeBrush" Color="#66000000" />
<SolidColorBrush x:Key="HyperlinkForegroundThemeBrush" Color="#FF4F1ACB" />
<SolidColorBrush x:Key="HyperlinkPointerOverForegroundThemeBrush" Color="#CC4F1ACB" />
<SolidColorBrush x:Key="HyperlinkPressedForegroundThemeBrush" Color="#994F1ACB" />
So if you have the following App.xaml.cs:
<Application.Resources>
<ResourceDictionary>
<SolidColorBrush x:Key="HyperlinkForegroundThemeBrush" Color="Green" />
</ResourceDictionary>
</Application.Resources>
You will get a green Hyperlink:
If you want the link to have underline, you can use the Underline-element. The XAML:
<TextBlock Width="400" TextWrapping="Wrap" VerticalAlignment="Center">
<Span FontSize="20">
This is an example of how Hyperlink can be used in a paragraph of text. It might be helpful for you look to
<Hyperlink NavigateUri="http://www.bing.com"><Underline>bing</Underline></Hyperlink>
for more answers in the future.
</Span>
</TextBlock>
And the result:
In my app I'm using
<Hyperlink TextDecorations="None" ...></Hyperlink>
to get rid of the underline.

Resources