Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何正确设置ListView的字符串格式_C#_Xaml_Xamarin - Fatal编程技术网

C# 如何正确设置ListView的字符串格式

C# 如何正确设置ListView的字符串格式,c#,xaml,xamarin,C#,Xaml,Xamarin,我正在用类中的对象填充ListView,但我看不到所有字段。有些确实表现得很好,有些根本就不好。我怀疑我的字符串格式有问题。谢谢你的帮助。另一方面,在调试时,ListView中未显示的类成员的值也不能在Watch中进行求值,这只给了我一个“{…}”,而不是一个具体的值- 我曾尝试在不同的线程上实现DatetimeToStringConverter,但这对我不起作用 C# 我希望ListView中的所有标签都按照它们的绑定进行填充。练习、分类、重复和Fmax都表现得很好。日期和重量根本不显示 编辑

我正在用类中的对象填充ListView,但我看不到所有字段。有些确实表现得很好,有些根本就不好。我怀疑我的字符串格式有问题。谢谢你的帮助。另一方面,在调试时,ListView中未显示的类成员的值也不能在Watch中进行求值,这只给了我一个“{…}”,而不是一个具体的值-

我曾尝试在不同的线程上实现DatetimeToStringConverter,但这对我不起作用

C#

我希望ListView中的所有标签都按照它们的绑定进行填充。练习、分类、重复和Fmax都表现得很好。日期和重量根本不显示


编辑:为RecordedLift添加了core

请显示
RecordedLift
的代码完成-我的错,对不起。@Jasony您正在对double和int应用StringFormat!!!我想这可能是个原因吧?@FreakyAli是的,但我在其他领域也这么做了。我明白StringFormat就是为了这个,不是吗?@Jason-关闭和打开计算机再次解决了问题,代码没有变化。一个干净的重建没有,它必须是一个重新启动(更可能的是,一个VS的重新启动)。虽然我非常喜欢VS作为最好的开发环境,但有时我真的很讨厌这些bug。谢谢你的支持!
public partial class LiftLog : ContentPage
{
    ObservableCollection<RecordedLift> RecordList;

    public LiftLog()
    {
        RecordList = new ObservableCollection<RecordedLift>();
        InitializeComponent();
        RecordedLifts.ItemsSource = RecordList;
    }
}
<ListView x:Name="RecordedLifts" ItemSelected="RecordedLifts_ItemSelected" HasUnevenRows="True">
    <ListView.ItemTemplate>
        <DataTemplate>
            <!-- <TextCell Text="{Binding Category}" Detail="{Binding Exercise}"/>-->
            <ViewCell>
                <ViewCell.ContextActions>
                    <MenuItem Clicked="MenuItem_Clicked" CommandParameter="{Binding .}" Text="More" />
                    <MenuItem Clicked="MenuItem_Clicked_1" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True" />
                </ViewCell.ContextActions>
                <StackLayout Orientation="Horizontal" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
                    <StackLayout HorizontalOptions="StartAndExpand">
                        <Label Text="{Binding Exercise}"/>
                        <Label Text="{Binding Category}" TextColor="Blue"/>
                    </StackLayout>
                    <StackLayout HorizontalOptions="CenterAndExpand" Orientation="Vertical">
                        <Label Text="{Binding Weight, StringFormat='{}{0:0} KG'}" />
                        <Label Text="{Binding Reps, StringFormat='{}{0:0} Reps'}" />
                    </StackLayout>
                    <StackLayout HorizontalOptions="EndAndExpand" Orientation="Vertical">
                        <Label Text="{Binding Fmax, StringFormat='1RM = \{0:0.00\}'}" />
                        <Label Text="{Binding Date, StringFormat='Lifted on-\{0:dd/MM/yy}'}" TextColor="Red" />
                    </StackLayout>
                </StackLayout>
            </ViewCell>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
public class RecordedLift
    {
        public string Category { get; set; }
        public DateTime Date { get; set; }
        public int Reps { get; set; }
        public double Weight { get; set; }
        public string Exercise { get; set; }
        public double Fmax { get; set; }
        public string Detail {
            get
            {
                string result = string.Format("{0:F2} ({1:F0} Reps with {2:F2} KG", Fmax, Reps, Weight);
                return result;
            }
            set { }
        }
    }