编辑:按照建议对 Observable 集合进行更改,但仍然不起作用:新代码如下所示:
private ObservableCollection<bool> _placeTypes = new ObservableCollection<bool>();
//private static bool[] _placeTypes { get; set; }
public ObservableCollection<bool> placeTypes
{
get
{
return _placeTypes;
}
set
{
_placeTypes = value;
placechange = true;
RaisePropertyChanged("placeTypes");
}
}
Oki,我有一个带有这种结构的 bool 数组的对象:
private bool[] _placeTypes { get; set; }
public bool[] placeTypes
{
get
{
return _placeTypes;
}
set
{
_placeTypes = value;
placechange = true;
RaisePropertyChanged("placeTypes");
}
}
对象以这种方式正确绑定到某些复选框:
<CheckBox x:Name="_1_Cafe" IsChecked="{Binding Path=placeTypes[0], Mode=TwoWay}" Content="Cafe" FlowDirection="RightToLeft" Width="429" HorizontalContentAlignment="Stretch" />
<CheckBox x:Name="_2_Pub" IsChecked="{Binding placeTypes[1], Mode=TwoWay}" Content="Pub" FlowDirection="RightToLeft" Width="429"/>
<CheckBox x:Name="_3_Chiringuito" IsChecked="{Binding placeTypes[2], Mode=TwoWay}" Content="Chiringuito" FlowDirection="RightToLeft" Width="429"/>
<CheckBox x:Name="_4_BeachClub" IsChecked="{Binding placeTypes[3], Mode=TwoWay}" Content="Beach Club" FlowDirection="RightToLeft" Width="429"/>
<CheckBox x:Name="_5_ClubDiscoteca" IsChecked="{Binding placeTypes[4], Mode=TwoWay}" Content="Club/Discoteca" FlowDirection="RightToLeft" Width="429"/>
<CheckBox x:Name="_6_Tetería" IsChecked="{Binding placeTypes[5], Mode=TwoWay}" Content="Tetería" FlowDirection="RightToLeft" Width="429"/>
<CheckBox x:Name="_7_Restaurante" IsChecked="{Binding placeTypes[6], Mode=TwoWay}" Content="Restaurante" FlowDirection="RightToLeft" Width="429"/>
而且我需要知道他们是否更改了使用此方法发送 Json 包:
if (Perfil.placechange == true)
{
int[] places = new int[7];
for (int i = 0; i < 6; i++)
{
if (Perfil.placeTypes[i] == true)
{
places[i] = i + 1;
}
}
preferencias.placeTypes = places;
launch = true;
}
paquete.preferencias = preferencias;
if (launch == true)
{
Uri url = new Uri("link");
string respuesta = await metodosJson.jsonPOST(url, paquete);
var paqueteprueba = JsonConvert.SerializeObject(paquete);
var respuestajson = JsonConvert.DeserializeObject<objetoslistas.setPreferencesoutput>(respuesta.ToString());
if (respuestajson.error == "")
{
Settings["timestamp"] = respuestajson.timestamp;
}
}
当我启动模拟器时,一切似乎都正常,复选框被标记或未标记,具体取决于布尔值是真还是假。但是当我改变其中任何一个的状态时,placechange 永远不会变为真。事实是,如果我查看完整的对象,布尔数组已经改变。任何的想法?