微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在ListView中切换不会触发

如何解决在ListView中切换不会触发

我正在列表视图中填充设置,但是我想让它保持通用状态,只是像这样设置类,但是当我切换值时,它不会触发命令 对于我的开关,我已经使用它添加了命令。 它在列表https://damienaicheh.github.io/xamarin/xamarin.forms/2019/05/17/how-to-add-command-to-a-switch-in-xamarin-forms-en.html

之外有效
public class Settings
{
    public string Type { get; set; }
    public bool Value { get; set; }
    public Command command { get; set; }
}

然后我正在加载这样的特定设置

public CustomSettingsviewmodel()
{
    LoadSetting();
   
}

private void LoadSetting()
{
    foreach (var setting in _customSettings.ScanSettings)
    {
        var detail = new Settings()
        {
            Type = setting.Type,Value = setting.Value,command = new Command<Settings>((value) => ExecutePageCommand(value))
        };
        Setting.Add(detail);
    }
}

命令

private void ExecutePageCommand(Settings settings)
{
    foreach (var result in _customSettings.ScanSettings.Where(d => d.Type == settings.Type))
    {
        var detail = new ScanSetting()
        {
            Value = settings.Value,};
    }
}
<Grid  BackgroundColor="{DynamicResource PageBackgroundColor}"  x:Name="grid" HorizontalOptions="FillAndExpand" ColumnSpacing="0">
  <!--Data-->
  <Label Grid.Row="0" Text ="{Binding Type}"   Style="{StaticResource SubLabelStyle}" HorizontalOptions="Start" Padding="10" VerticalOptions="End"   />
  <Switch Grid.Row="0"  IsToggled="{Binding Value}" HorizontalOptions="End" VerticalOptions="CenterandExpand" >
    <Switch.Behaviors>
      <control:SwitchBehavIoUr Command="{Binding  command}" />
    </Switch.Behaviors>
  </Switch>
</Grid>    

但是,我不确定如何更改确切属性上开关的值,因此它只会更改一个值。你能请教吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。