Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.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
如何将数据绑定到Xamarin表单中的“footer”_Xamarin_Xamarin.forms - Fatal编程技术网

如何将数据绑定到Xamarin表单中的“footer”

如何将数据绑定到Xamarin表单中的“footer”,xamarin,xamarin.forms,Xamarin,Xamarin.forms,如何将数据绑定到Xamarin表单中ListView中的页脚,这里我需要将count_值传递给页脚 <ListView x:Name="listView"> <ListView.Footer> <StackLayout> <Label Text="{Binding Count}" BackgroundColor="Gray"></Label>

如何将数据绑定到Xamarin表单中ListView中的页脚,这里我需要将count_值传递给页脚

<ListView  x:Name="listView">
        <ListView.Footer>
            <StackLayout>
                <Label Text="{Binding Count}" BackgroundColor="Gray"></Label>
            </StackLayout>
        </ListView.Footer>
        <ListView.ItemTemplate>
            <DataTemplate>
                <ViewCell>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="2*"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="2*"/>
                        </Grid.ColumnDefinitions>
                        <Image Source="{Binding image}" WidthRequest="50" HeightRequest="50" Grid.Column="0" VerticalOptions="Center"/>
                        <StackLayout Grid.Column="1">
                            <Label Text="{Binding FullName}" TextColor="#f35e20" HorizontalTextAlignment="Center"/>
                        </StackLayout>
                        <StackLayout Grid.Column="2">
                            <Label Text="{Binding SoccerStatus}" HorizontalTextAlignment="Center" TextColor="#503026"/>
                        </StackLayout>
                        <StackLayout Grid.Column="3">
                            <Label Text="{Binding CurrentDate}" HorizontalTextAlignment="Center" TextColor="#503026"/>
                        </StackLayout>
                    </Grid>
                </ViewCell>
            </DataTemplate>
        </ListView.ItemTemplate>

    </ListView>
下面是DisplayCount从数据库中获取计数

 public void DisplayCount()
        {
           var datetoday = DateTime.Now.ToString("ddMMyyyy");
           var count_in = (from x in conn.Table<SoccerAvailability>().Where(x => string.Equals(x.SoccerStatus, "IN", StringComparison.OrdinalIgnoreCase) && x.CurrentDate == datetoday) select x).Count();

        }

你一定要数一数

<Label Text="{Binding Count}" BackgroundColor="Gray"></Label>

您需要指定页脚的绑定上下文

默认情况下,对于列表视图中的页脚、页眉和模板,其绑定上下文将是当前显示的项。因此,在这种情况下,Count必须是ItemsSource中项目的公共属性。将计数绑定指向视图模型

<Label Text="{Binding BindingContext.Count, Source={x:Reference xNameSetForCurrentPage}" BackgroundColor="Gray"></Label>
xNameSetForCurrentPage是在页面最上面的元素处设置的x:Name=Name,所有xmlns内容都位于该元素处


现在获取数据库异常SQLite异常没有这样的函数 相等于

这是因为SQLLite linq无法识别string.Equals方法。对于一个条件,可以使用ToListSync将其转换为列表。然后使用equals筛选c列表对象:

var datetoday = DateTime.Now.ToString("ddMMyyyy");

var items = await conn.Table<SoccerAvailability>().Where(x => x.CurrentDate == datetoday).ToListAsync();
var finalsItems = items.Where(x => string.Equals(x.SoccerStatus, "IN", StringComparison.OrdinalIgnoreCase)).ToList();

Count = finalsItems.Count();
编辑2:

如果未使用视图模型,请为页脚标签设置名称:

<ListView.Footer>
    <StackLayout>
        <Label x:Name="FooterLabel" BackgroundColor="Gray"></Label>
    </StackLayout>
</ListView.Footer>

但是如何将值中的count_传递给Text={Binding count}。我已在ViewModelCount=Count\u中将Count设置为公共属性;获取数据库异常,其中x=>x.SoccerStatus==in您应该采取措施防止坏数据进入数据库。使用枚举而不是字符串。或者,您可以修改属性的setter以始终强制使用一致的大小写。我将尝试使用它现在获取数据库异常SQLite exception no此类函数equals lu:我已按照某人的建议将输入文本转换为大写。在设置断点时,我收到count_in=1,但是计数没有显示在页脚文本={Binding count}中,它显示为0@what is this BindingContext=new PageViewModel@soccerway这是页面的绑定上下文,如果要使用视图模型处理数据:​​​​​​​. 如果您的页面没有使用绑定。请查看我的编辑。现在已成功显示此项,如果我们在“视图”中有单个项要显示,为什么我们需要选择绑定属性。我们可以使用与您修改的相同的方法,对吗?@soccerway在使用绑定之前,我们应该设置控件的绑定上下文。它指出了他们使用的是什么视图模型。我猜您是指列表视图,您可以使用listview的items源设置视图单元格的绑定上下文。请仔细阅读我上面发布的关于绑定的文档。
// Set your page's binding context
BindingContext = new PageViewModel();

public class PageViewModel : INotifyPropertyChanged
{
    int count;
    public int Count
    {
        set
        {
            if (count != value)
            {
                count = value;
                onPropertyChanged();
            }
        }
        get
        {
            return count;
        }
    }

    public event PropertyChangedEventHandler PropertyChanged;
    void onPropertyChanged([CallerMemberName] string propertyName = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
    }
}
<ListView.Footer>
    <StackLayout>
        <Label x:Name="FooterLabel" BackgroundColor="Gray"></Label>
    </StackLayout>
</ListView.Footer>
//...
FooterLabel.Text = finalsItems.Count().ToString();