首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将所有转换为true的开关更改为ListView?

如何将所有转换为true的开关更改为ListView?
EN

Stack Overflow用户
提问于 2019-04-25 02:55:44
回答 1查看 37关注 0票数 0

我有一个页面,有一个ListView,它已经切换到用户选择他想要的寄存器。然后,我创建了一个用户单击的主开关,我希望将所有其他参数都更改为ListView,设置为true或false。

我怎么能这样做呢?

XAML

<Switch x:Name="IsSelectAll" Toggled="OnChangeSelectAll" IsToggled="False" HorizontalOptions="EndAndExpand" ></Switch>

<ListView x:Name="GrupoDeProdutos"
                      SeparatorVisibility="Default">
                <ListView.ItemTemplate>
                    <DataTemplate>
                        <ViewCell>
                            <StackLayout Orientation="Horizontal">
                                <StackLayout HorizontalOptions="StartAndExpand">
                                    <Label Text="{Binding title}" HorizontalOptions="StartAndExpand" TextColor="Default"></Label>
                                </StackLayout>
                                <Switch x:Name="{Binding id}" IsToggled="{Binding active}"></Switch>
                            </StackLayout>                           
                        </ViewCell>
                    </DataTemplate>
                </ListView.ItemTemplate>
            </ListView>

控制器

public partial class PopUpGrupoProdutoUsuario : PopupPage{        
        private List<TableModel> listaModel = new List<TableModel>();       

        public PopUpGrupoProdutoUsuario()
        {
            InitializeComponent();            
        }


        //select all switch true/false
        private void OnChangeSelectAll(object sender, ToggledEventArgs args){            
            foreach (TableModel t in this.listaModel){                 
                t.active = args.Value;                
            }            
        }

        //class listview model
        public class TableModel{
            public int id                       { get; set; }
            public String title                 { get; set; }
            public Boolean active                { get; set; }

            public TableModel() { }

            public TableModel(int id, String title, Boolean active) {
                this.id = id;
                this.title = title;
                this.active= active;
            }
        }



    }

编辑

//class listview model
        public class TableModel : INotifyPropertyChanged        {
            public event PropertyChangedEventHandler PropertyChanged;

            public int id
            {
                get { return id; }
                set
                {
                    if(id != value)
                    {
                        id = value;
                        NotifyPropertyChanged();
                    }
                }
            }


            public String title
            {
                get { return title; }
                set
                {
                    if(title != value)
                    {
                        title = value;
                        NotifyPropertyChanged();
                    }
                }
            }


            public Boolean ativo
            {
                get { return ativo; }
                set {
                    if(ativo != value){
                        ativo = value;
                        NotifyPropertyChanged();
                    }
                }
            }

            public TableModel() {
                if (DesignMode.IsDesignModeEnabled)
                {
                    this.id = 0;
                    this.title = "default";
                    this.ativo = false;
                }
            }

            public TableModel(int id, String title, Boolean ativo) {
                if (DesignMode.IsDesignModeEnabled){
                    this.id = id;
                    this.title = title;
                    this.ativo = ativo;
                }                
            }

            protected virtual void NotifyPropertyChanged([CallerMemberName] string propertyName = ""){
                PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
            }


        }

错误

=================================================================
    Native Crash Reporting
=================================================================
Got a SIGSEGV while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries 
used by your application.
=================================================================
04-22 11:34:59.495 E/mono-rt (20272): /proc/self/maps:
=================================================================
    Basic Fault Adddress Reporting

04-22 11:34:59.495 E/mono-rt (20272): 12c00000-32c00000 rw-p 00000000 00:01 10738                              /dev/ashmem/dalvik-main space (region space) (deleted)
04-22 11:34:59.495 E/mono-rt (20272): 5af61000-5af65000 r-xp 00000000 08:06 331                                /system/bin/app_process32
04-22 11:34:59.495 E/mono-rt (20272): 5af66000-5af67000 r--p 00004000 08:06 331                                /system/bin/app_process32
04-22 11:34:59.495 E/mono-rt (20272): 5af67000-5af68000 rw-p 00000000 00:00 0 
04-22 11:34:59.495 E/mono-rt (20272): 6f101000-6f2e7000 rw-p 00000000 08:13 105905                             /data/dalvik-cache/x86/system@framework@boot.art
04-22 11:34:59.495 E/mono-rt (20272): 6f2e7000-6f3a4000 rw-p 00000000 08:13 105906                             /data/dalvik-cache/x86/system@framework@boot-core-libart.art
04-22 11:34:59.495 E/mono-rt (20272): 6f3a4000-6f3e1000 rw-p 00000000 08:13 105907                             /data/dalvik-cache/x86/system@framework@boot-conscrypt.art=================================================================
Memory around native instruction pointer (0xc318029f):0xc318028f  8b 4d f8 8d 64 24 00 90 90 90 8b 45 08 89 04 24  .M..d$.....E...$
0xc318029f  e8 b4 ff ff ff 89 45 f0 8b 4d f8 8d 64 24 00 90  ......E..M..d$..
0xc31802af  90 90 8b 45 f0 8b f0 8b 4d f8 8d 64 24 00 90 90  ...E....M..d$...
0xc31802bf  90 8b c6 8b 4d f8 8d 64 24 00 90 90 90 8d 65 fc  ....M..d$.....e.

No native Android stacktrace (see debuggerd output).

=================================================================
    Managed Stacktrace:
=================================================================
      at TableModel:get_title <0x00047>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableModel:get_title <0x0004b>
      at TableMod
EN

回答 1

Stack Overflow用户

发布于 2019-04-26 14:49:17

您的代码将在无限循环中结束。你的"Title“属性就是原因。创建一个私有成员"Title“和一个公共属性"title”。这应该能起到作用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55836817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档