Net maui collectionview in mopups (PopupPage) error because of visualstategroup

Sami 966 Reputation points
2023-11-06T00:58:40.9733333+00:00

Net maui collectionview in mopups (PopupPage) error because of visualstategroup..... when is disable no error but not working events of visualstategroup ...any idea ? thanks

<mopups:PopupPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" 
        xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
        x:Class="CitysM.Views.PlusViews.Advertisement.AdvertisementPopup" 
        xmlns:mopups="clr-namespace:Mopups.Pages;assembly=Mopups"
        BackgroundColor="Transparent"              
        CloseWhenBackgroundIsClicked="False">

<mopups:PopupPage.Resources>  
       
<conv:LanguageConverter x:Key="langConverter" />              

</mopups:PopupPage.Resources>

     <mopups:PopupPage.Content>

<CollectionView  x:Name="TabAd"
	Grid.Row="2"
HorizontalScrollBarVisibility="Never"
ItemsSource="{Binding AdsMenu}"
SelectionMode="Single"
VerticalScrollBarVisibility="Never">
                <CollectionView.ItemsLayout>
                    <LinearItemsLayout Orientation="Horizontal"  />
                </CollectionView.ItemsLayout>
                <CollectionView.ItemTemplate>
                    <DataTemplate>
                        <Grid x:Name="tabGrid" Padding="15,4,15,0"  BackgroundColor="{DynamicResource BackColor}" Style="{StaticResource TabGrid}">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroupList>
                                    <VisualStateGroup x:Name="CommonStates">
                                        <VisualState x:Name="Normal" >
                                            <VisualState.Setters>
                                                <Setter Property="BackgroundColor" Value="{DynamicResource BackColor}" />
                                                <Setter Property="Label.TextColor" Value="{DynamicResource MainTextColor}" />
                                            </VisualState.Setters>
                                        </VisualState>
                                        <VisualState x:Name="Selected">
                                            <VisualState.Setters>
                                                <Setter Property="BackgroundColor" Value="{Binding BColor}" TargetName="tabGrid" />
                                                <Setter Property="Label.TextColor" Value="{StaticResource White}" TargetName="tabLabel" />
                                            </VisualState.Setters>
                                        </VisualState>
                                    </VisualStateGroup>
                                </VisualStateGroupList>
                            </VisualStateManager.VisualStateGroups>
                            <Label
                            x:Name="tabLabel"        
				FontSize="{StaticResource SmallFontSize}"
                HorizontalTextAlignment="Center"
                Text="{Binding TabTitle,Converter={StaticResource langConverter}}"    
                VerticalTextAlignment="Center" />
                        </Grid>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>

    </mopups:PopupPage.Content> 
</mopups:PopupPage>    
    
    
Developer technologies | .NET | .NET MAUI
{count} votes

1 answer

Sort by: Most helpful
  1. Sami 966 Reputation points
    2023-11-07T02:06:40.6566667+00:00
    <?xml version="1.0" encoding="utf-8" ?>
    <ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                 x:Class="MyProject.Controls.CollectionViews.Tabs"
                 x:Name="TabView">
            <CollectionView x:Name="Tab"
    	Grid.Row="1"
    HorizontalScrollBarVisibility="Never"
    ItemsSource="{Binding Source={x:Reference TabView}, Path=ItemsSource, Mode=OneWay}"
    SelectionMode="Single"
    VerticalScrollBarVisibility="Never">
            <CollectionView.ItemsLayout>
                <LinearItemsLayout Orientation="Horizontal"  />
            </CollectionView.ItemsLayout>
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <Grid x:Name="tabGrid" Padding="15,0"  BackgroundColor="{DynamicResource BackColor}" HeightRequest="40">
                        <Label x:Name="tabLabel" FontSize="{StaticResource SmallFontSize}" HorizontalTextAlignment="Center" VerticalTextAlignment="Center" Text="{Binding Title}" />
                    </Grid>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    
    </ContentView>
    
    
    
    public partial class Tabs : ContentView 
    {     
    
    public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create("ItemsSource", typeof(ObservableCollection<MyModel>), typeof(Tabs), new ObservableCollection<MyModel>());     
    
    public ObservableCollection<MyModel> ItemsSource     {         get { return (ObservableCollection<MyModel>)GetValue(ItemsSourceProperty); }         set { SetValue(ItemsSourceProperty, value); }     }     
    
    public Tabs() 	{ 		
    
    InitializeComponent();         
    Content.BindingContext = this; 
    
    //setting visualstates      
       
    Setter backgroundColorSetter = new Setter() { Property = Grid.BackgroundColorProperty, Value = new Binding("BackColor") };         
    Setter textColorSetter = new Setter() { Property = Label.TextColorProperty, Value = Colors.White, TargetName = "tabLabel" };         
    VisualState stateSelected = new VisualState() { Name = CommonStates.Selected, Setters = { backgroundColorSetter, textColorSetter } };         
    VisualState stateNormal = new VisualState() { Name = CommonStates.Normal };         
    VisualStateGroup visualStateGroup = new VisualStateGroup() { Name = nameof(CommonStates), States = { stateSelected, stateNormal } };         
    VisualStateGroupList visualStateGroupList = new VisualStateGroupList() { visualStateGroup };         
    Setter vsgSetter = new Setter() { Property = VisualStateManager.VisualStateGroupsProperty, Value = visualStateGroupList };         
    Style style = new Style(typeof(Grid)) { Setters = { vsgSetter } };   
          
    Resources.Add(style); 
    
      }
    }
    
    //In mopups
    
    <mopups:PopupPage  
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"             
    x:Class="MyProject.Views.Page2"              
    xmlns:mopups="clr-namespace:Mopups.Pages;assembly=Mopups"                                     
    xmlns:c="clr-namespace:MyProject.Controls"             
    Shell.NavBarIsVisible="False"              
    BackgroundColor="Transparent"             
    CloseWhenBackgroundIsClicked="False">
    
      <mopups:PopupPage.Content>
     <c:Tabs   ItemsSource="{Binding MyMenu}"/>
        </mopups:PopupPage.Content>  
    </mopups:PopupPage>
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.