- Home
- Forum
- Xamarin.Forms
- Call Api for it !
Call Api for it !
I have a api that is giving json data! I have to set a datasource for the combobox these api.But i am not getting any data in combobox. Help me !
public InspectionForm ()
{
InitializeComponent();
getdata();
}
public async Task<IEnumerable<InspectionModel>> GetProcess()
{
var client = new HttpClient();
string result = await client.GetStringAsync(Url);
return JsonConvert.DeserializeObject<IEnumerable<InspectionModel>>(result);
}
public async void getdata()
{
ProcessPicker.DataSource = await GetProcess();
ProcessPicker.DisplayMemberPath = "Name";
ProcessPicker.BindingContext = await GetProcess();
}
this is xaml.cs code
this is xaml code for the picker
<Label
FontFamily="{StaticResource Montserrat-Medium}"
Margin="0,24,0,4"
HeightRequest="18"
FontSize="12"
Text="Process *"
TextColor="{DynamicResource Gray-800}" />
<border:SfBorder
BorderColor="{Binding Source={x:Reference ProcessPicker}, Path=IsFocused, Converter={StaticResource ColorConverter}, ConverterParameter=3}"
Style="{StaticResource BusinessFormBorderStyle}">
<combobox:SfComboBox
x:Name="ProcessPicker"
SelectedValue="{Binding Process, Mode=TwoWay}"
Style="{StaticResource ComboBoxStyle}"
Watermark="Choose Process"
VerticalOptions="CenterAndExpand" DataSource="">
<combobox:SfComboBox.DropDownButtonSettings>
<combobox:DropDownButtonSettings>
<combobox:DropDownButtonSettings.View>
<Label
FontFamily="{StaticResource FontIcons}"
FontSize="25"
HorizontalTextAlignment="Center"
Text="{StaticResource DropDownButtonIcon}"
TextColor="{DynamicResource Gray-600}"
VerticalTextAlignment="Center" />
</combobox:DropDownButtonSettings.View>
</combobox:DropDownButtonSettings>
</combobox:SfComboBox.DropDownButtonSettings>
</combobox:SfComboBox>
</border:SfBorder>
SIGN IN To post a reply.
1 Reply
1 reply marked as answer
SS
Suganya Sethuraman
Syncfusion Team
August 20, 2020 06:21 AM UTC
Hi Dhruv,
We have checked the reported query and created a sample based on the REST Service in SfComboBox. Please find the sample from the following link.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBox_Online-1583644180
In this sample, we have get the details from the REST service and set as DataSource to ComboBox in the ValueChanged event as like below code snippet,
Code Snippet:
We have checked the reported query and created a sample based on the REST Service in SfComboBox. Please find the sample from the following link.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/ComboBox_Online-1583644180
In this sample, we have get the details from the REST service and set as DataSource to ComboBox in the ValueChanged event as like below code snippet,
Code Snippet:
|
var content = await response.Content.ReadAsStringAsync();
Items = JsonConvert.DeserializeObject<FullData>(content); |
Please check if the sample satisfies your requirement and if not provide additional details like pictorial representation of your requirement which will be helpful for us to provide the solution at the earliest.
Regards,
Suganya Sethuraman.
Marked as answer
SIGN IN To post a reply.