如何绑定可观察集合计数值在文本块Windows Phone

本文关键字:文本 Phone Windows 集合 何绑定 绑定 观察 | 更新日期: 2023-09-27 18:10:44

如何在windows phone的textblock中绑定可观察集合Count value

  <Grid Margin="440,26,10,0"  Grid.Row="1" HorizontalAlignment="Right">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="*"/>
                                        </Grid.ColumnDefinitions>
                                        <StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,0,0">
                                            <Grid Height="25" MinWidth="25">
                                                <Grid.Background>
                                                    <ImageBrush ImageSource="{Binding Image}"  Stretch="Fill"/>
                                                </Grid.Background>
                                                <TextBlock Name="Message_Count" Text="{Binding CollectionCount}" Foreground="White" FontSize="20" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                                            </Grid>
                                        </StackPanel>
                                    </Grid>
List<CountMsg> retrieved = dbConnCount.Table<CountMsg>().ToList<CountMsg>();
            dbCount = new ObservableCollection<CountMsg>(retrieved);

我想绑定dbCount。

如何绑定可观察集合计数值在文本块Windows Phone

下面是一个例子:

MainWindow.cs:

    ObservableCollection<CountMsg> dbCount;
    public int CollectionCount
    {
        get
        {
            return dbCount.Count;
        }
    }
    public MainWindow()
    {
        InitializeComponent();
        DataContext = this;
        List<CountMsg> retrieved = dbConnCount.Table<CountMsg>().ToList<CountMsg>();
        dbCount = new ObservableCollection<CountMsg>(retrieved);
    }
Xaml:

<Window x:Class="MainWindow">
    ....
    <TextBlock Text="{Binding CollectionCount}" ... />
    ....
</Window>