首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >单击Xamarin.Forms时,ListView ViewCell背景色更改为橙色,但未初始化为颜色。

单击Xamarin.Forms时,ListView ViewCell背景色更改为橙色,但未初始化为颜色。
EN

Stack Overflow用户
提问于 2020-02-10 13:00:57
回答 3查看 2.1K关注 0票数 4

这是我的密码

代码语言:javascript
运行
复制
<ListView x:Name="listViewClient"  ItemsSource="{Binding Client}" HasUnevenRows="True">
            <ListView.ItemTemplate>
                <DataTemplate>
                    <ViewCell >


                        <Grid  Margin="10">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="5"/>
                                <ColumnDefinition />
                            </Grid.ColumnDefinitions>
                            <BoxView  Grid.Column="0" Color="#84DCC6"/>
                            <StackLayout Grid.Column="1" Padding="20, 10">

                                <Frame BorderColor="WhiteSmoke">
                                    <StackLayout>
                                <Label Text="Name:" FontSize="16" />
                                <Label FontSize="Medium" Text="{Binding Name}" FontAttributes="Bold" />
                                    </StackLayout>
                                </Frame>
                                <Frame BorderColor="WhiteSmoke">
                                    <StackLayout>
                                    <Label Text="Adress:"  FontSize="16"/>
                                <Label FontSize="Medium" Text="{Binding Adress}" FontAttributes="Bold"/>
                                    </StackLayout>
                                </Frame>
                                <Frame BorderColor="WhiteSmoke">
                                    <StackLayout>
                                    <Label Text="Place:"  FontSize="16"/>
                                    <Label FontSize="Medium" Text="{Binding Place}" FontAttributes="Bold" />
                                    </StackLayout>
                                </Frame>

                                <Frame BorderColor="WhiteSmoke" >
                                    <Grid >

                                    <StackLayout Grid.Column="0">
                                    <Label Text="Mobile:"  FontSize="16"/>
                                    <Label  FontSize="Medium" Text="{Binding Mobile}" FontAttributes="Bold" />
                                    </StackLayout>
                                        <Button Grid.Column="1" Text="Call" Clicked="PovikajPartnerClicked" BackgroundColor="#84DCC6"></Button>
                                    </Grid>
                                </Frame>
                                <Frame BorderColor="WhiteSmoke">
                                    <StackLayout>
                                        <Label Text="Е-mail:"  FontSize="16"/>
                                        <Label FontSize="Medium" Text="{Binding EMAIL}" FontAttributes="Bold" />
                                    </StackLayout>
                                </Frame>
                                <Frame BorderColor="WhiteSmoke">
                                    <StackLayout>
                                        <Label Text="LAW:"  FontSize="16"/>
                                        <Label FontSize="Medium" Text="{Binding LAW}" FontAttributes="Bold" />
                                    </StackLayout>
                                </Frame>

                                <Frame BorderColor="WhiteSmoke
                                       ">
                                    <StackLayout>
                                <Label Text="SECNUM:"  FontSize="16"/>
                                <Label FontSize="Medium" Text="{Binding SECNUM}" FontAttributes="Bold" />
                                    </StackLayout>
                                </Frame>

                            </StackLayout>
                        </Grid>
                    </ViewCell>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

我不知道从哪里得到橙色背景颜色时,我点击列表。从代码中可以看出,我没有选择samo背景颜色。是否有默认的点击事件使颜色变成橙色?我什么都试过了,但找不到有什么地方我忘了加颜色。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2020-05-21 12:09:37

我知道这可能有点晚了,但我希望这会对某些人有所帮助,只需在AppName.Android/Resources/values下运行您的styles.xml文件,并在您的主题中添加以下内容:

代码语言:javascript
运行
复制
<item name="android:colorActivatedHighlight">@android:color/transparent</item>
票数 7
EN

Stack Overflow用户

发布于 2020-02-10 13:14:16

这是您的ListView的默认选择颜色,它来自您的应用程序的主题,Xamarin默认在模板中设置了这个主题来解决这个问题,只需将以下内容添加到您的ListView中

代码语言:javascript
运行
复制
<ListView SelectionMode="None" ..../>
票数 4
EN

Stack Overflow用户

发布于 2022-01-27 22:43:16

我在聚会上迟到了,但我在Grepper上找到的这个解决方案可能会有帮助。它很简单,并且对每个内容页都是唯一的。可以使用ViewCell抽头事件更改当前单元格和前一个单元格的背景色。

XAML:

代码语言:javascript
运行
复制
<ListView.ItemTemplate>
    <DataTemplate>
        <ViewCell Tapped="ViewCell_Tapped" >
            <Label Text="{Binding Name}" TextColor="DarkGoldenrod" />
        </ViewCell>
    </DataTemplate>
</ListView.ItemTemplate>

在代码中添加:

代码语言:javascript
运行
复制
ViewCell lastCell;
private void ViewCell_Tapped(object sender, System.EventArgs e)
{
    if (lastCell != null)
        lastCell.View.BackgroundColor = Color.Transparent;
    var viewCell = (ViewCell)sender;
    if (viewCell.View != null)
    {
        viewCell.View.BackgroundColor = Color.LightGray;
        lastCell = viewCell;
    }
} 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60150987

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档