Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Objects as Choices in MaterialTextInput #56

Closed
fabcall opened this issue Jan 28, 2019 · 6 comments
Closed

Objects as Choices in MaterialTextInput #56

fabcall opened this issue Jan 28, 2019 · 6 comments
Labels
enhancement New feature or request valid This issue/bug/feature request is valid

Comments

@fabcall
Copy link

fabcall commented Jan 28, 2019

Is your feature request related to a problem? Please describe.
Possibility to use objects as "Choices" in the MaterialTextField. Nowadays, this control only support an array of strings.

Describe the solution you'd like
Just like the built-in Picker solution, it would be nice if we could just set an ItemsSource attribute and ItemDisplayBinding to bind the value which should be shown.

Describe alternatives you've considered
Using the built-in Picker solution.

@contrix09 contrix09 self-assigned this Jan 29, 2019
@contrix09 contrix09 added enhancement New feature or request valid This issue/bug/feature request is valid labels Jan 29, 2019
@contrix09
Copy link

Update on this feature request. I tried to implement the current Xamarin.Form.Picker logic that allows binding to a property of an item in a list, but it was hard to reverse engineer the logic.

What I was able to do is to use a converter to get the property value of the item, and put the property name in the converter parameter. So in Xaml, it would look like this:

<material:MaterialTextField Choices="{Binding Companies, Converter={StaticResource ChoiceConverter}, ConverterParameter=CompanyName}"
     HelperText="*Required"
     InputType="Choice"
     Placeholder="Company" />

@fabcall
Copy link
Author

fabcall commented Feb 8, 2019

I guess it's a decent solution, but what could be done if we want to retrieve the Selected Item? Maybe I'm diverging a little from original issue, but let's say you want the MaterialTextInput to act exactly like a picker. So, we could have a OnSelectedItemEvent. Following the Companies example, we would have a SelectedCompany property on ViewModel. When user interacts and selects a choice (from the converted string array), we could dispatch an OnSelectedItemEvent). Ultimately, we could simply set SelectedCompany by SelectedIndex.

@contrix09
Copy link

Hmm. Currently, if the input type is set to Choice, the control uses IMaterialDialog.SelectChoiceAsync method to get the value to display in the control's text. The dialog only supports specifying the choice by passing a collection of string parameter, and returns the string that was selected. The ChoiceConverter gets the collection of objects and only returns a collection of string values back to the control. There is no way to determine the selected object from the original collection, more so if there are multiple items that have the same, let's say, company name.

Perhaps for the mean time, I can implement your suggested solution but I will also add a command property (say ItemSelectedCommand?) counter part. I can use LINQ to determine and pass the object that was selected to the event/command.

@contrix09
Copy link

Hi, I removed the ChoiceConverter implementation. You can now bind a collection of objects or string. There is a new property ChoicesDisplayName which you can set which property to show when you use a custom collection of objects.

@fabcall
Copy link
Author

fabcall commented Feb 17, 2019

Hi Dustin! Nice! I will try ASAP. Thanks a lot for this awesome plugin.

@contrix09
Copy link

Thanks. Package is still building, it will be visible for download ~30 mins.

@contrix09 contrix09 removed their assignment Sep 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request valid This issue/bug/feature request is valid
Projects
None yet
Development

No branches or pull requests

1 participant