如何绑定文本块Windows Phone中的observable collection Count值

时间:2015-09-02 07:08:57

标签: c# wpf xaml windows-phone-8

如何在列表框的Windows Phone中的textblock中绑定可观察集合的计数值

  <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);

我想在textblock中绑定dbCount.Count;

1 个答案:

答案 0 :(得分:0)

以下是一个例子:

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>