Xamarin ListView Issue - xamarin.ios

I am beginer on Xamarin. What did I do wrong here. I am trying to add Conext Menu to ListView and compiler is not happy with this.
<ListView x:Name="VehicleList">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell
ImageSource="152x152#1x.png"
Text="{Binding Title}"
Detail="{Binding SubTitle}"
TextColor="#f35e20"
DetailColor="#503026" />
<!-- adding this caused error
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnDelete" CommandParameter="{Binding .}"
Text="Archive"
IsDestructive="True" />
</ViewCell.ContextActions>
</ViewCell>
-->
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

You are defining two viewcells in one data template. this is not possible!
You should create a DataTemplateSelector and declare the ViewCells in separate classes. Then you can make the selector choose a viewcell based on the logic implemented in the DataTemplateSelector. The xamarin documentation has a nice explanation: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/

Related

CollectionView SelectionChanged method not triggering when tapping the item directly .NET MAUI

I'm creating a CollectionView in .net MAUI where i'm using Frame control inside the data template. As a result of that, when I tap directly on the item, the SelectionChanged method is not being triggered and will trigger only if I click on the frame border or outside of it. Below sample code and picture. Is this a bug in MAUI or I'm doing something wrong? I had the same setup in Xamarin and it was working with no issues.
XAML
<CollectionView x:Name="scheduleItemsCollection"
SelectionChanged="scheduleItemsCollection_SelectionChanged"
SelectionMode="Single"
>
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Vertical"
Span="2"
/>
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="5" RowSpacing="0">
<Frame CornerRadius="40" BorderColor="Gray">
<StackLayout Spacing="0" BackgroundColor="White">
<Label Text="{Binding bookingDayArabic}" />
<Label Text="{Binding bookingDateD}" />
<StackLayout Orientation="Horizontal">
<Label Text="{Binding slotsAvailable}" HorizontalOptions="CenterAndExpand" />
<Label Text="عدد الطلبات:"/>
</StackLayout>
</StackLayout>
</Frame>
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Yes, it is the case as you said. Thanks for your support and feedback for maui.
I have created a new issue about this problem.
You can follow it up here: https://github.com/dotnet/maui/issues/9567.
Have a nice day.
This worked for me:
<Frame.GestureRecognizers>
<TapGestureRecognizer Tapped="Section_Tapped"/>
</Frame.GestureRecognizers>

Hiding Tab(s) in MaterialDesign Tabablz TabablzControl

I would like to bind a TabItem's visibility property to a bool property in my viewmodel (via converter, true=visible false=collapsed), but the visibility property on the TabItem does not hide the tab. I don't want to hide all of the tab, just individual ones.
Does anyone know how this can be achieved?
I wanted to have something similiar. I asked the developer about it, but this is not possible with Dragablz (which is Tabablz). The TabItem itself is not used in dragablz.
A workaround for this could be using materialdesign radiobuttons as tab headers instead of dragablz. Radio buttons can be collapsed.
<StackPanel Orientation="Horizontal" Margin="4">
<RadioButton x:Name="FirstTab" Style="{StaticResource MaterialDesignTabRadioButton}" Margin="4" Visibility="Collapsed" IsChecked="True" Content="FIRST" />
<RadioButton Style="{StaticResource MaterialDesignTabRadioButton}" Margin="4" IsChecked="False" Content="SECOND" />
<RadioButton Style="{StaticResource MaterialDesignTabRadioButton}" Margin="4" IsChecked="False" Content="THIRD" />
</StackPanel>
now you just have to create some grids below them, which have their visibility bound to the IsChecked attribute of the corresponding radio button. This way you can show only the grid which is bound to the currently selected radio button. You need a bool2visibility converter, maybe the default one shipped with wpf works (the one in my example is a custom one).
<Grid Visibility="{Binding IsChecked, Source={x:Reference FirstTab}, Converter={StaticResource Bool2VisibilityConverter}}">

Overflowing button in Xamarin Forms

I've got a mockup with a screen I don't know how to implement properly:
I'm wondering how to position that Login button (and the "sign in with" block). Without "Login", it would be quite easy with a StackLayout. But this makes it less easy and I'm searching for a simple solution.
I presume it's feasible with an AbsoluteLayout with position calculations in the codebehind, but that makes the whole page more complicated than it looks.
The white block is a Frame that's used everywhere in the app. It's not specific to the login page, so I want to reuse it elsewhere.
How would you do that?
I think you can use a Grid... with 3 rows.
Rows 1 and 2 have the same height.
"Login data" (User/pwd...) occupy row 0 and 1
Button occupy row 2 and 2
For Example
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" x:Class="fev_ventilazione_smartwatch.Pages.MyPageTest">
<ContentPage.Content>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="8*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="4*" />
<ColumnDefinition Width="2*" />
<ColumnDefinition Width="4*" />
</Grid.ColumnDefinitions>
<Label Text="TEXT" Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Grid.ColumnSpan="3" BackgroundColor="Aqua"/>
<Button Text="BUTTON" Grid.Row="1" Grid.Column="1" Grid.RowSpan="2" BackgroundColor="Fuchsia"/>
</Grid>
</ContentPage.Content>
</ContentPage>
Produce
I presume it's feasible with an AbsoluteLayout with position
calculations in the codebehind, but that makes the whole page more
complicated than it looks.
Yes you are right. It is feasible with AbsoluteLayout. But its not as complicated as it seems.
Construct your basic elements first:
White container/StackLayout for login details
Login Button.
Facebook/Google buttons in a horizontal StackLayout.
"OR" Label
"Create An Account" Button
Put them in AbsoluteLayout and define their AbsoluteLayout.LayoutFlags as well as AbsoluteLayout.LayoutBounds.
Now key here is to understand that how Absolute Layout works?
You can find that out from this page: Absolute Layout
I have wrote some code to achieve something similar below. But make sure you learn it fully and understand everything before you can use it in your app:
<ContentPage.Content>
<ScrollView BackgroundColor="Silver">
<AbsoluteLayout Margin="30" >
<StackLayout BackgroundColor="White" HeightRequest="150" Spacing="20" Padding="10" VerticalOptions="FillAndExpand"
AbsoluteLayout.LayoutBounds="0,0,1,250" AbsoluteLayout.LayoutFlags="XProportional,YProportional,WidthProportional"
>
<Entry Text="Login" HeightRequest="30"/>
<Entry Text="Password" HeightRequest="30" IsPassword="true" />
<Label Text="FORGOT YOUR PASSOWORD?" HorizontalTextAlignment="End"/>
</StackLayout>
<Button
Text="LOGIN"
FontAttributes="Bold"
BackgroundColor="Maroon"
TextColor="White"
HeightRequest="70"
WidthRequest="70"
AbsoluteLayout.LayoutBounds=".5,215,70,70" AbsoluteLayout.LayoutFlags="XProportional" BorderRadius="35"
/>
<StackLayout
Orientation="Horizontal"
HorizontalOptions="EndAndExpand"
AbsoluteLayout.LayoutBounds="1,270,0.5,70" AbsoluteLayout.LayoutFlags="XProportional,WidthProportional"
>
<Button Text="Facebook"/>
<Button Text="Google"/>
</StackLayout>
<Label Text="OR" HorizontalTextAlignment="Center"
AbsoluteLayout.LayoutBounds="0.5,350,50,50"
AbsoluteLayout.LayoutFlags="XProportional"
/>
<Button
Text="CREATE AN ACCOUNT" Margin="15"
BackgroundColor="White" TextColor="Maroon"
BorderColor="Maroon" BorderWidth="1"
BorderRadius="0"
HorizontalOptions="FillAndExpand"
AbsoluteLayout.LayoutBounds="0.5,370,1,150"
AbsoluteLayout.LayoutFlags="XProportional,WidthProportional"
/>
</AbsoluteLayout>
</ScrollView>
</ContentPage.Content>
And here is the result:
NOTE: You can achieve the same look using RelativeLayout as well.
Hope this helps.

Androids RelativeLayout for Windows Phone

I'm currently trying to design a table for contact information including a column for icons like telephone, email or similar symbols and I want to align them with the text from the next column
icon | Telephone:
| +1212354567
icon | Email:
| x#y.com
Is there any Layout which can be compared in functionality to Androids RelativeLayout? I tried to work with the Grid Layout but this seems to be error prone and not exact enough. I don't want to divide my layout into columns and rows, instead I want to describe their position as it is used in RelativeLayout (toLeft, toRight, AlignParentBottom etc.).
The StackPanel can be compared to the LinearLayout, which I want to avoid as it is not suitable for my current design.
Is there any comparison between Windows Phone and Android Layouts on which I can orientate? This one is incomplete and does not give advise for the RelativeLayout.
I know you said you did not want to use a Grid but I feel that you have to in this case.
I would structure it with both a grid and stack panels though.
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<!-- Image for first row item -->
<Image Grid.Column="0" Grid.Row="0" Source="icon-url" />
<!-- Container for the details of the first row item -->
<StackPanel Grid.Column="1" Grid.Row="0">
<TextBlock Text="Telephone:" />
<TextBlock Text="+1212354567" />
</StackPanel>
<!-- Image for second row item -->
<Image Grid.Column="0" Grid.Row="1" Source="icon-url" />
<!-- Container for the details of the second row item -->
<StackPanel Grid.Column="1" Grid.Row="1">
<TextBlock Text="Email:" />
<TextBlock Text="x#y.com" />
</StackPanel>
<!-- Just add rows to the grid to continue the list -->
</Grid>
There is no panel that compares, but someone that was adventurous could create one. There are many articles on how to do this, but here's one for reference. http://www.switchonthecode.com/tutorials/wpf-tutorial-creating-a-custom-panel-control
That said, there's no reason not to use Grid for what you're trying to do. It's not "error prone" or "not exact enough". SharedSizeGroup should become your friend here, though.

'ToolTip' cannot have a logical or visual parent

I have the following problem. I keep getting 'ToolTip' cannot have a logical or visual parent error when i try to style tooltip for the toggle button. What went wrong? When i take out the tooltip control under ToggleButton.ToolTip it works !
<ToggleButton x:Name="toggle" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" Margin="0,4,0,0" VerticalAlignment="Top" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
<ToggleButton.ToolTip>
<ToolTip Style="{StaticResource tooltipstyle}">
<TextBlock Background="Transparent"/>
</ToolTip>
</ToggleButton.ToolTip>
</ToggleButton>
If you write code like this using property element syntax, you call already the constructor of the ToolTip class.
<ToggleButton.ToolTip>
<TextBlock></TextBlock>
</ToggleButton.ToolTip>
There is no need to instantiate another ToolTip inside like this...
<ToggleButton.ToolTip>
<ToolTip Style="{StaticResource tooltipstyle}">
<TextBlock Background="Transparent"/>
</ToolTip>
</ToggleButton.ToolTip>
Besides, on my system (using .NET 4.5) there is no error.
It seems that WPF can handle both versions meanwhile as intended by the developer.

Resources