亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在 Xamarin 中使用 ObervableCollection 的 ListView

在 Xamarin 中使用 ObervableCollection 的 ListView

C#
DIEA 2023-06-25 13:36:26
我想根據可用選項顯示按鈕,但在實現它時遇到了一些麻煩。如果有人可以看一下我的代碼,那就太好了。該系列很好,但沒有顯示任何按鈕。我已經嘗試過以下操作:public ObservableCollection<Button> shownButtons { get; set; } = new ObservableCollection<Button>();private void ActionSelector(){Button button;            foreach (var serviceAction in basedata)            {                switch (serviceAction.ChangeType)                {                    case ServiceTodoChangeType.Accept:                        button = new Button()                        {                            //Command = AcceptServiceCommand,                            Text = Translations.Accept                        };                        shownButtons.Add(button);                        break;                    case ServiceTodoChangeType.ServicePause:                        button = new Button()                        {                            Command = BreakCommand,                            Text = Translations.ServicePause                        };                        shownButtons.Add(button);                        break;}}}XAML:<ListView ItemsSource="shownButtons">                        <ListView.ItemTemplate>                            <DataTemplate>                                <ViewCell>                                    <Button                                      Text="{Binding Text}"                                      Command="{Binding Command}">                                    </Button>                                </ViewCell>                            </DataTemplate>                        </ListView.ItemTemplate>                    </ListView>
查看完整描述

1 回答

?
郎朗坤

TA貢獻1921條經驗 獲得超9個贊

我收到錯誤...


我忘記綁定源了。


使固定:


 <ListView ItemsSource="{Binding shownButtons}">

                            <ListView.ItemTemplate>

                                <DataTemplate>

                                    <ViewCell>

                                        <Button 

                                         Text="{Binding Text}" 

                                         Command="{Binding Command}">

                                        </Button>

                                    </ViewCell>

                                </DataTemplate>

                            </ListView.ItemTemplate>

                        </ListView>


查看完整回答
反對 回復 2023-06-25
  • 1 回答
  • 0 關注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號