我是Xamarin Forms的新手,我知道有很多有用的控件。我正在寻找一个可以扩展以在网格中显示数据的控件,如下例所示。
更新资料
模型:
public class Phone
{
public string mobile { get; set; }
public string home { get; set; }
public string office { get; set; }
}
public class Contact
{
public string id { get; set; }
public string name { get; set; }
public string email { get; set; }
public string address { get; set; }
public string gender { get; set; }
public Phone phone { get; set; }
}
public class ContactList …Run Code Online (Sandbox Code Playgroud) 我需要在列表中长按和短按
我正在使用效果来长按列表中的项目(ListView/CollectionView),但是当该效果起作用时,短按(点击)不起作用!
我的问题是:我是否需要创建另一个短点击效果版本,或者我可以以某种方式同时拥有两者吗?我到处搜索,没有任何信息可以帮助我找到解决方案......
我一直在我的存储库中使用此代码,但无法使两者同时工作。
<CollectionView
x:Name="carsCollection"
ItemsSource="{Binding Cars}"
SelectionMode="Single"
SelectionChangedCommand="{Binding TapCommand}"
SelectionChangedCommandParameter="{Binding Source={x:Reference carsCollection}, Path=SelectedItem}"
BackgroundColor="Orange">
<CollectionView.ItemTemplate>
<DataTemplate>
<ContentView>
<StackLayout
effects:LongPressedEffect.Command="{Binding Path=BindingContext.LongTapCommand, Source={x:Reference ThisPage}}"
effects:LongPressedEffect.CommandParameter="{Binding .}">
<Label Text="CollectionView: Long Press works but not normal selection" />
<StackLayout.Effects>
<effects:LongPressedEffect />
</StackLayout.Effects>
</StackLayout>
</ContentView>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
Run Code Online (Sandbox Code Playgroud)
包含命令的 ViewModel 位于此处。
我正在为我的项目使用 xamarin.forms 列表视图。设计如下:
<ContentView x:Name="Overlay" IsVisible="False"
VerticalOptions="Center" HorizontalOptions="Center" Margin="10,20,10,30"
AbsoluteLayout.LayoutBounds="0,0,1,1" AbsoluteLayout.LayoutFlags="All" BackgroundColor="LightGray">
<StackLayout Spacing="0">
<StackLayout Padding="20" BackgroundColor="#9C6114" Spacing="0">
<Label Text="Country Name" TextColor="White" FontAttributes="Bold" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"></Label>
</StackLayout>
<StackLayout Spacing="0">
<ListView x:Name="CountryList" HasUnevenRows="True" Margin="10,0,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Orientation="Horizontal">
<Switch IsToggled="{Binding IsToggle}"></Switch>
<Label Text="{Binding CountryName}"></Label>
</StackLayout>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.Footer>
<StackLayout Orientation="Horizontal">
<Button x:Name="btncancel" Text="Cancel" TextColor="White" BackgroundColor="#9C6114" HorizontalOptions="CenterAndExpand" Clicked="btncancel_Clicked"></Button>
<Button x:Name="btnsubmit" Text="Submit" TextColor="White" BackgroundColor="#9C6114" HorizontalOptions="CenterAndExpand" Clicked="btnsubmit_Clicked"></Button>
</StackLayout>
</ListView.Footer>
</ListView>
</StackLayout>
</StackLayout>
</ContentView>
Run Code Online (Sandbox Code Playgroud)
对于此列表视图,列表视图下方有空余空间。我无法删除列表视图中的多余空格。请参阅所附图片。在此处输入图片说明
请帮我解决这个问题。
在Xamarin.forms中使用ListView时,在选择项目时,该项目仍然具有相当难看的背景颜色.我可以禁用此功能吗?
这是我的代码:
<StackLayout>
<ListView x:Name="FoodList" HasUnevenRows="True" CachingStrategy="RecycleElement" ItemTapped="OnItemTapped">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<StackLayout Padding="0,15,0,0" >
<StackLayout Orientation="Horizontal" BackgroundColor="White" >
<Image Source="{Binding image_url}" Aspect="AspectFill" HeightRequest="200" WidthRequest="200"/>
<StackLayout Orientation="Vertical">
<Label Text="{Binding food_name}" TextColor="Black" Style="{StaticResource MainLisTtext}" />
<Label Text="{Binding price}" TextColor="Black" Style="{StaticResource SubLisTtext}" />
<Label Text="{Binding food_description}" TextColor="Black" Style="{StaticResource SubLisTtext}" />
</StackLayout>
</StackLayout>
</StackLayout>
</ViewCell>vc
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
Run Code Online (Sandbox Code Playgroud) 我想在我的 Xamarin.Forms 项目中添加很棒的字体,我已经将它添加到了项目中。然后我将 FontFamily 添加到这样的标签中:
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Padding="15">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="9*" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" Text="" FontSize="20">
<Label.FontFamily>
<OnPlatform x:TypeArguments="x:String">
<On Platform="iOS" Value="Font Awesome 5 Free" />
<On Platform="Android" Value="fa-regular-400.ttf#Font Awesome 5 Free Regular" />
</OnPlatform>
</Label.FontFamily>
</Label>
<Label Grid.Column="1" Text="{Binding Title}" FontSize="20"/>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)
但是当我将这些硬编码的东西更改为这样的可绑定属性时:
<Label Grid.Column="0" Text="{Binding FontAwesomeIconText}" FontSize="20">
Run Code Online (Sandbox Code Playgroud)
并在 c# 中这样设置
menuItems = new List<DrawerMenuItem>
{
new DrawerMenuItem {Id = MenuItemType.Browse, Title="Browse", FontAwesomeIconText = "" },
new DrawerMenuItem {Id …Run Code Online (Sandbox Code Playgroud) 我正在使用Xamarin.Forms 2.4构建社交帖子共享应用程序,它与我的API通讯。
我有PostsPage,它使用PostDataViewModel将ObservableCollection加载到PostsPage中定义的ListView中。列表视图的数据模板指向视图文件。但是,在Post View模板中,我可以绑定到“我的帖子模型”的各个属性,但是无法绑定到ViewModel上存在的命令。我没有运气就尝试了x:Reference。
我的模特:
using System;
using System.Collections.Generic;
namespace SOD_APP_V2.Model
{
public class PostDataModel
{
public string ID { get; set; }
public string Title { get; set; }
public string Message { get; set; }
public string Image { get; set; }
public string SocialMedia { get; set; }
public string AvailableTime { get; set; }
public string Audiences { get; set; }
public string Topics { get; set; }
public List<PostVersion> Versions { get; set; }
public …Run Code Online (Sandbox Code Playgroud) data-binding mvvm xamarin xamarin.forms xamarin.forms.listview