【问题标题】:FlowListView one separate label with FlowColumnCount = "1"FlowListView 一个单独的标签,FlowColumnCount = "1"
【发布时间】:2020-02-15 18:52:22
【问题描述】:

使用 FlowListView 后,我得到以下结果:

但是Emergency应该是其他颜色加上其他点击事件和FlowColumnCount的大小=“1”

这是以下代码:

<?xml version="1.0" encoding="utf-8" ?>

            <flv:FlowListView.FlowColumnTemplate>
                <DataTemplate>
                    <Frame BackgroundColor="Purple" Margin="5">
                        <Label HorizontalOptions="Fill" 
                        VerticalOptions="Fill" 
                        TextColor="White"
                        XAlign="Center"
                        YAlign="Center" 
                        Text="{Binding Text}"/>
                    </Frame>
                </DataTemplate>
            </flv:FlowListView.FlowColumnTemplate>
        </flv:FlowListView>
    </StackLayout>
</ContentPage.Content>

这是 MockDataStore:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using DLToolkit.Forms.Controls;
using EscapeHaarlem.Models;

namespace EscapeHaarlem.Services
{
public class MockDataStore : IDataStore<Item>
{
    List<Item> items;

    public MockDataStore()
    {
        FlowListView.Init();
        items = new List<Item>();
        //this.items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 1", Description = "This is an item description." });
        //this.items.Add(new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 2", Description = "This is an item description." });

        var mockItems = new List<Item>
        {
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 1", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 2", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 3", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 4", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 5", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 6", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 7", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 8", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 9", Description="This is an item description." },
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 10", Description="This is an item description."},
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 11", Description="This is an item description."},
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 12", Description="This is an item description."},
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 13", Description="This is an item description."},
            new Item { Id = Guid.NewGuid().ToString(), Text = "Hint 14", Description="This is an item description."},
            new Item { Id = Guid.NewGuid().ToString(), Text = "Emergency", Description="This is an item description."},
        };

        foreach (var item in mockItems)
        {
            items.Add(item);
        }
    }

    public async Task<bool> AddItemAsync(Item item)
    {
        items.Add(item);

        return await Task.FromResult(true);
    }

    public async Task<bool> UpdateItemAsync(Item item)
    {
        var oldItem = items.Where((Item arg) => arg.Id == item.Id).FirstOrDefault();
        items.Remove(oldItem);
        items.Add(item);

        return await Task.FromResult(true);
    }

    public async Task<bool> DeleteItemAsync(string id)
    {
        var oldItem = items.Where((Item arg) => arg.Id == id).FirstOrDefault();
        items.Remove(oldItem);

        return await Task.FromResult(true);
    }

    public async Task<Item> GetItemAsync(string id)
    {
        return await Task.FromResult(items.FirstOrDefault(s => s.Id == id));
    }

    public async Task<IEnumerable<Item>> GetItemsAsync(bool forceRefresh = false)
    {
        return await Task.FromResult(items);
    }
}

}

我怎样才能使紧急按钮具有其他颜色大小和点击事件?

提前致谢

【问题讨论】:

  • 可以吗?

标签: c# android xaml xamarin


【解决方案1】:

你的意思是你想让Emergency 一个单独的列并有一个单独的点击事件,对吧?

如果是的话,你可以用ListView.Footer显示,然后你可以单独定义它的颜色,点击事件,比如:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         xmlns:d="http://xamarin.com/schemas/2014/forms/design"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         mc:Ignorable="d"
         xmlns:flv="clr-namespace:DLToolkit.Forms.Controls;assembly=DLToolkit.Forms.Controls.FlowListView"
         x:Class="App18.FlowListPage">
<ContentPage.Content>
    <StackLayout>
        <flv:FlowListView FlowColumnCount="2"   
            SeparatorVisibility="Default"   
            HasUnevenRows="True"  
            FlowItemTappedCommand="{Binding ItemTappedCommand}"   
            FlowItemsSource="{Binding Items}">

            <flv:FlowListView.FlowColumnTemplate>
                <DataTemplate>
                    <Frame BackgroundColor="Purple"  
            Margin="5">
                        <Label HorizontalOptions="Fill"   
                VerticalOptions="Fill"   
                TextColor="White"  
                XAlign="Center"  
                YAlign="Center"   
                Text="{Binding Text}"/>
                    </Frame>
                </DataTemplate>
            </flv:FlowListView.FlowColumnTemplate>
            <flv:FlowListView.Footer>

                <StackLayout>
                    <Button Text="Emergency" BackgroundColor="Accent" Clicked="Button_Clicked"></Button>
                </StackLayout>

            </flv:FlowListView.Footer>
        </flv:FlowListView>
    </StackLayout>
</ContentPage.Content>

【讨论】:

  • 我得到:“在类型 'FlowListView' 中找不到可附加属性 'Footer'。”
  • @Xandervandenberg 我展示了完整的 xaml 代码,你可以检查一下
  • 你找到解决办法了吗?
【解决方案2】:

您需要将属性触发器用作seen in the docs

伪代码:

    <Label HorizontalOptions="Fill" 
                            VerticalOptions="Fill" 
                            TextColor="White"
                            XAlign="Center"
                            YAlign="Center" 
                            Text="{Binding Text}">

                     <Label.Triggers>
       <Trigger TargetType="Label" //TargetType sets the element type
                 Property="Text" //Element property that will be watched
                  Value="Emergency">//Value that causes the trigger
            <Setter Property="BackgroundColor" Value="Yellow" />
     //The effects the trigger will have (can be several)
           </Trigger>
     </Label.Triggers>

    </Label>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-18
    • 2013-10-05
    • 2018-11-16
    • 1970-01-01
    • 2012-08-30
    • 1970-01-01
    • 2020-07-19
    相关资源
    最近更新 更多