if (OxygenTank.IsChecked == true) query.Where = "OxygenTank = 'Oxygen Tank'"; else if (ServiceAnimal.IsChecked == true) query.Where = "ServiceAnimal = 'Service Animal'"; else if (Walker.IsChecked == true) query.Where = "Walker = 'Walker'";
<RadioButton x:Name="OxygenTank" Click="RadioButton_Click" GroupName="SpecialNeeds" Foreground="White" Content="Oxygen Tank"> </RadioButton> <RadioButton x:Name="ServiceAnimal" Click="RadioButton_Click" GroupName="SpecialNeeds" Foreground="White" Content="Service Animal" > </RadioButton> <RadioButton x:Name="Walker" Click="RadioButton_Click" GroupName="SpecialNeeds" Foreground="White" Content="Walker" > </RadioButton>
Solved! Go to Solution.
<StackPanel x:Name="CheckBoxPanel" Orientation="Vertical" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" AllowDrop="True"> <TextBlock x:Name="QueryData" Text="Do you have any special needs for your trip?" Foreground="White" FontSize="20" FontWeight ="ExtraBold" Grid.Row="0" Margin="15,5,15,1" HorizontalAlignment="Center" > </TextBlock> <CheckBox x:Name="OxygenTank" Content="Oxygen Tank" Tag="OxyygenTank"/> <CheckBox x:Name="ServiceAnimal" Content="Service Animal" Tag="ServiceAnimal"/> <CheckBox x:Name="Walker" Content="Walker" Tag="Walker"/> <CheckBox x:Name="Wheelchair" Content="Wheelchair" Tag="Wheelchair"/> <CheckBox x:Name="Scooter" Content="Scooter" Tag="Scooter"/> <Button Height="30" Width="60" Content="Search" Click="Button_Click"/> </StackPanel>
private void Button_Click(object sender, RoutedEventArgs e) { //Setup stuff from before.... string where = null; //This uses a foreach with a little Linq, it will look at every Child of the StackPanel and if it is a CheckBox that is Checked then go into the loop foreach (CheckBox checkBox in CheckBoxPanel.Children.OfType<CheckBox>().Where(checkBox => checkBox.IsChecked == true)) { AppendWhere(ref where, checkBox); } query.Where = where; queryTask.ExecuteAsync(query); } private void AppendWhere(ref string where, CheckBox checkBox) { string checkBoxQuery = checkBox.Tag + " = '" + checkBox.Content + "'"; if ( where == null ) { where = checkBoxQuery; } else { where += " OR " + checkBoxQuery; } }
private void CheckBoxClick(object sender, RoutedEventArgs e) { // Query task initialization. QueryTask queryTask = new QueryTask("MapServer Web Address"); queryTask.ExecuteCompleted += QueryTask_ExecuteCompleted; queryTask.Failed += QueryTask_Failed; // Query task parameters. Return geometry, state Query query = new Query(); query.ReturnGeometry = true; query.OutFields.AddRange(new string[] { "OxygenTank", "ServiceAnimal", "Walker", "Wheelchair", "Scooter"}); if (OxygenTank.IsChecked == true) query.Where = "OxygenTank = 'Oxygen Tank'"; else if (ServiceAnimal.IsChecked == true) query.Where = "ServiceAnimal = 'Service Animal'"; else if (Walker.IsChecked == true) query.Where = "Walker = 'Walker'"; else if (Wheelchair.IsChecked == true) query.Where = "Wheelchair = 'Wheelchair'"; else if (Scooter.IsChecked == true) query.Where = "Scooter = 'Scooter'"; queryTask.ExecuteAsync(query); }
<StackPanel Orientation="Vertical" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="3" AllowDrop="True"> <TextBlock x:Name="QueryData" Text="Do you have any special needs for your trip?" Foreground="White" FontSize="20" FontWeight ="ExtraBold" Grid.Row="0" Margin="15,5,15,1" HorizontalAlignment="Center" > </TextBlock> <CheckBox x:Name="OxygenTank" Click="CheckBoxClick" Content="Oxygen Tank"/> <CheckBox x:Name="ServiceAnimal" Click="CheckBoxClick" Content="Service Animal"/> <CheckBox x:Name="Walker" Click="CheckBoxClick" Content="Walker"/> <CheckBox x:Name="Wheelchair" Click="CheckBoxClick" Content="Wheelchair"/> <CheckBox x:Name="Scooter" Click="CheckBoxClick" Content="Scooter"/> </StackPanel>
<StackPanel x:Name="CheckBoxPanel" Orientation="Vertical" Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="3" AllowDrop="True"> <TextBlock x:Name="QueryData" Text="Do you have any special needs for your trip?" Foreground="White" FontSize="20" FontWeight ="ExtraBold" Grid.Row="0" Margin="15,5,15,1" HorizontalAlignment="Center" > </TextBlock> <CheckBox x:Name="OxygenTank" Content="Oxygen Tank" Tag="OxyygenTank"/> <CheckBox x:Name="ServiceAnimal" Content="Service Animal" Tag="ServiceAnimal"/> <CheckBox x:Name="Walker" Content="Walker" Tag="Walker"/> <CheckBox x:Name="Wheelchair" Content="Wheelchair" Tag="Wheelchair"/> <CheckBox x:Name="Scooter" Content="Scooter" Tag="Scooter"/> <Button Height="30" Width="60" Content="Search" Click="Button_Click"/> </StackPanel>
private void Button_Click(object sender, RoutedEventArgs e) { //Setup stuff from before.... string where = null; //This uses a foreach with a little Linq, it will look at every Child of the StackPanel and if it is a CheckBox that is Checked then go into the loop foreach (CheckBox checkBox in CheckBoxPanel.Children.OfType<CheckBox>().Where(checkBox => checkBox.IsChecked == true)) { AppendWhere(ref where, checkBox); } query.Where = where; queryTask.ExecuteAsync(query); } private void AppendWhere(ref string where, CheckBox checkBox) { string checkBoxQuery = checkBox.Tag + " = '" + checkBox.Content + "'"; if ( where == null ) { where = checkBoxQuery; } else { where += " OR " + checkBoxQuery; } }