问题描述
我正在列表视图中填充设置,但是我想让它保持通用状态,只是像这样设置类,但是当我切换值时,它不会触发命令 对于我的开关,我已经使用它添加了命令。 它在列表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 (将#修改为@)