I’m in the middle of writing a Xamarin Forms app and today I needed to add in a contacts search page, and remembered that James Montemagno had created a plugin that exposes contacts in a platform neutral manner so I downloaded it and used it in my app.
I also wanted to add a search bar, and again there’s a control in XF for that, so I ended up with (somewhat simplified) the following XAML…
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<SearchBar x:Name="search" Placeholder="Search">
</SearchBar>
<ListView Grid.Row="1" ItemsSource="{Binding FilteredContacts}"
IsGroupingEnabled="true" GroupDisplayBinding="{Binding Key}"
GroupShortNameBinding="{Binding Key}">
<ListView.ItemTemplate>
<DataTemplate>
<TextCell Text="{Binding Name}" TextColor="Black"
Detail="{Binding PhoneNumber}" DetailColor="Gray">
</TextCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
I have removed some of the XAML as it’s not that important to this post (it’s available in the download). Now, with that in place (and a load of code in the view model which I’ll get to in a minute) I got a UI as follows…
So far so good. Then I needed to hook up the search box, and as I’m using XAML (and if you’re not, you should give it a try as it’s way easier to create UI’s using it) I needed a way to bind to the search box to that I could respond to the TextChanged event.
Another excellent package that you’ll want to use it the Xamarin.Behaviors package by Corrado – massive thanks to him for putting this together, it’s excellent!
Behaviors to the rescue
By adding a behavior into the XAML, I can handle an event – so in this case I added the following to the SearchBar…
<SearchBar x:Name="search" Placeholder="Search">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<b:EventToCommand EventName="TextChanged"
Command="{Binding SearchTextChanged}"
CommandParameter="{Binding Text, Source={x:Reference search}}"/>
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</SearchBar>
This hooks the TextChanged event of the search bar, calls the SearchTextChangedCommand on my view model, and passes through the value of the Text property of the search bar. Yay!.
Or not.
The problem I found was that my command was being passed a string, but it was the text before the ne character was entered, so say I pressed ‘X’ in an empty search bar, my code would be called with an empty string. Pressing ‘A’ next, my command would get ‘X’, and pressing ‘M” next, my code would get ‘XA’. I was always getting the data just prior to the new character – so I guess that the TextChanged event should be more clearly termed as the TextChanging event.
Anyway, I needed to fix this – so looked at the actual event and it contains two properties, the current text and the new value. All I needed to do was get the new vale of the event arguments and I’d be away.
To the best of my knowledge there is no way to bind to the event arguments, you need to write some additional code (this was true in WPF and Silverlight, I’ve done exactly the same there too). So, I cranked out a new behavior that attaches to the SearchBar’s TextChanged event, and calls the command with the new value of the text property. My XAML is therefore this…
<SearchBar x:Name="search" Placeholder="Search">
<b:Interaction.Behaviors>
<b:BehaviorCollection>
<bh:SearchBarTextChanged Command="{Binding SearchTextChanged}"/>
</b:BehaviorCollection>
</b:Interaction.Behaviors>
</SearchBar>
Here I'm using my SearchBarTextChanged behavior to hook to the SearchTextChanged command, and sure enough now when I type in the search bar I get the desired effect. Excellent!
Filtering in code
In the view model I use James’ contacts plugin to select all contacts that have a mobile phone, and that have at least a forename or surname (my real code blew up on a colleagues iPhone as he has a contact with just a company name). I tuck this list away as the source, and then create a filtered collection from the source and the filter statement.
CrossContacts.Current.PreferContactAggregation = false;
var hasPermission = CrossContacts.Current.RequestPermission().Result;
if (hasPermission)
{
// First off convert all contacts into ContactViewModels...
var vms = CrossContacts.Current.Contacts.Where(c => Matches(c))
.Select(c => new ContactViewModel(c));
// And then setup the contact list
var grouped = from contact in vms
orderby contact.Surname
group contact by contact.SortByCharacter into contactGroup
select new Grouping(contactGroup.Key, contactGroup);
foreach (var g in grouped)
{
_contacts.Add (g);
_filteredContacts.Add (g);
}
}
The above code uses some Linq to select all contacts and group them by first character of their surname. I created a simple Matches(contact) function that checks that the contact has a mobile phone number and also that they have one of forename or surname.
Then I have the code that is called to filter the collection when you type text into the search bar...
private void FilterContacts(string filter)
{
_filteredContacts.Clear ();
if (string.IsNullOrEmpty(filter))
{
foreach (var g in this.Contacts)
_filteredContacts.Add (g);
}
else
{
// Need to do some filtering
foreach (var g in this.Contacts)
{
var matches = g.Where (vm => vm.Name.Contains (filter));
if (matches.Any())
{
_filteredContacts.Add (new Grouping(g.Key, matches));
}
}
}
}
This is a bit ropey but does the trick. As the collection is an ObservableCollection, any changes are shown in the UI immediately.
Code
I’ve created a simple example project (the one shown above) that you can download. Hopefully this will help someone out. I’ve not tried this on Android or Windows Phone as yet, but as none of the code is in the platform specific library I can’t see any reason for it not to work on those platforms too.
Bye for now!
490 comments:
«Oldest ‹Older 401 – 490 of 490This topic doesn’t get enough attention. American IV provides strong medical insights in their article on Can Drinking Too Much Water Cause Diarrhea. Great resource for understanding safe hydration.
Sun Associates is a highly reliable Health Insurance Consultant in Erode, offering clear guidance and personalized support to help individuals and families choose the right medical insurance plans. Their team explains policy benefits, coverage options, and claim procedures in a simple and professional manner. They also provide excellent assistance during claim settlement, ensuring a smooth and stress-free experience. Whether you need individual health insurance, family coverage, or specialized policies like cardiac or cancer insurance, Sun Associates is a trusted choice in Erode for complete health protection.
TripLodge Universe offers travelers a smart and Affordable Hotel Staywithout compromising comfort. Designed for guests who value convenience, cleanliness, and cost-efficiency, TripLodge Universe provides well-appointed rooms, essential amenities, and a welcoming atmosphere at a price that fits every budget.
Finding reliable academic support can make a huge difference when dealing with complex finance topics and tight deadlines. Many students struggle with financial analysis, case studies, and theoretical concepts, which is why professional guidance becomes essential. Getting Finance assignment help from qualified marketing and finance professionals ensures well-researched, structured, and plagiarism-free work that meets UK academic standards. With expert insights, clear explanations, and timely delivery, students can better understand difficult concepts while improving their grades and confidence. It’s a smart way to balance academic pressure while maintaining quality and accuracy in every assignment.
Great website with interesting insights and well-presented content. Really enjoyed exploring the articles and the perspective shared here.
Also sharing helpful resources: UI/UX Course in Kochi by Login360 and Digital Marketing Course by Login360
Interesting blog with thoughtful insights and well-written content. I really enjoyed browsing through the articles and learning from the perspectives shared here.
Also sharing helpful resources: UI/UX Course in Kochi by Login360 and Digital Marketing Course by Login360
Thank you for sharing this informative website. Personal blogs and professional websites like this are great for sharing knowledge, ideas, and experiences with a wider audience online. Such platforms help readers explore useful insights and stay connected with different topics and discussions.
Continuous learning is important in the tech world. Programs like Login360 help learners gain practical skills in
Data Science and Full Stack Development
Great article on RNI Registration Online. The process of registering a newspaper or magazine with the Registrar of Newspapers for India can be complex, but this guide explains it clearly. Businesses looking for expert assistance can explore Agile Regulatory for professional support with RNI registration services in India.
Love the range of posts and the thoughtful perspectives you share here it’s really engaging for curious readers. For those also interested in boosting practical skills for the tech world, checking out a Java Certification Course in Coimbatore or a Python Training Institute in Coimbatore can be a great way to build expertise. Thanks for the insightful content!
Interesting website with helpful insights into programming and software development. Articles that explain technical concepts and developer tools are very valuable for learners and professionals who want to improve their coding skills. Blogs like this also show how knowledge sharing within the developer community helps others solve problems and learn new technologies. Promoting technical content online is equally important today. Anyone interested in online growth strategies can explore a digital marketing course in Chennai to understand SEO and content promotion.
There is no single astrologer officially recognized as the “Top Astrologer in the World.” Astrology is a belief-based field, and many astrologers from different cultures are considered great based on their influence, writings, and predictions. However, several astrologers are widely regarded as the most famous or influential in world history.
1. Nostradamus
• Lived: 1503–1566
• Famous for the book Les Prophéties containing prophetic quatrains.
• Known worldwide for predictions about future events.
• Often called the most famous astrologer in history.
2. Varahamihira
• A 6th-century Indian astrologer and mathematician.
• One of the Navaratnas (nine gems) in the court of King Chandragupta II.
• Wrote important works like Brihat Samhita and Pancha-Siddhantika.
3. Abu Ma'shar al-Balkhi
• Lived: 787–886
• Considered one of the greatest astrologers of the Islamic Golden Age.
• His writings strongly influenced medieval European astrology.
4. William Lilly
• Lived: 1602–1681
• Author of the famous astrology book Christian Astrology.
• Very influential in Western astrology.
5. B. V. Raman
• One of the most respected modern Vedic astrologers.
• Founder of The Astrological Magazine.
• Helped popularize Indian astrology worldwide.
6. Surya Narayan Vyas
• A renowned astrologer from Ujjain.
• He is credited with recommending the date 15 August 1947 for India’s independence celebration and received the Padma Bhushan award.
https://www.sundeepkochar.com/services
Great article! The way you explained the topic is very clear and helpful. For students who are interested in building programming skills, courses like Java Certification Course in Coimbatore and Python Training Institute in Coimbatore can be a good option to start a career in software development.
Posts like these make complex topics easier to understand and spark curiosity. That same practical, hands‑on learning makes a big difference in tech careers too. Programs like Login360 help with real exposure. Their Java Course and Python Course build strong skills.
Really enjoying the content here it’s thoughtful and engaging! Posts like this make the blog a great place to learn and reflect. If you’re also interested in building skills that are useful in today’s digital world, you might want to explore a Digital Marketing Training Institute in Coimbatore and a UI UX Design Course in Coimbatore. Expanding your digital and design skills alongside the great insights here can open up exciting opportunities!
Really enjoying the content here it’s engaging and thoughtful! I appreciate how you share insights that make readers pause and think. If you’re also looking to grow your professional skill set in today’s digital world, you might want to explore a Digital Marketing Training Institute in Coimbatore and a UI UX Design Course in Coimbatore. Building digital marketing and design skills alongside the great content here can open up some exciting opportunities!
Really enjoyed exploring this blog! The content feels thoughtful and well-expressed, making it both engaging and easy to read. It’s always great to come across blogs that share meaningful ideas and perspectives.
For anyone interested in building strong programming skills and starting their coding journey, this resource might be helpful:
Java Course for Beginners
The website appears to be a personal portfolio or professional site associated with Morgan Skinner, likely showcasing work, projects, or background in programming and tech. It reflects experience in software development and a career built around coding and technology. Overall, it presents a professional, personal-brand style online presence.
IT Jobs Without Coding – Complete Beginner Guide
If you’re struggling with coding tasks, getting reliable Python Assignment Help UK can make a real difference in both understanding and grades. Professional guidance ensures your concepts are clear, from basics to advanced topics, without unnecessary stress. It’s especially helpful when deadlines are tight and accuracy matters. Learning from qualified experts also improves your long-term coding confidence. Overall, it’s a practical way to stay on track and achieve better academic results.
For anyone looking to improve their technical skills alongside blogging, this resource could be useful:
Java Course for Beginners
Thanks for providing such an easy and accessible blogging platform!
Great post really insightful and helpful for anyone improving their commit messages! For readers also curious about building an online presence or learning how to promote content more effectively, this beginner‑friendly guide on digital marketing basics is worth checking out: What is Digital Marketing? simple, clear, and very informative!
Great post! I really enjoyed reading this and found the explanation very clear and easy to follow.
It’s always helpful to come across content that breaks things down so simply for beginners.
I’ve been exploring this topic recently, and your insights added a lot of value.
For anyone who wants a deeper understanding, I also found this useful guide on
What is Digital Marketing?
which explains the fundamentals in a very beginner-friendly way.
This is very helpful content. Adding another useful link: Digital Marketing Training in Chennai
Good work! Appreciate the effort you put into this. Also visit: Digital Marketing Training in Chennai
Massage Therapy is a hands-on technique that involves manipulation of the soft tissues of the body, including muscles, tendons, and ligaments, for the purpose of promoting relaxation, enhancing circulation, and relieving pain.
Massage Therapy is the manual therapy that includes the manipulation of the soft tissues of the body, which include the muscles, tendons, and ligaments, with the main objective of promoting relaxation, increasing circulation, and relieving pain.
Good explanation! Check out Learn UI UX Design Course Online.
Finding the best privacy cafe in Udaipur can be challenging, but The Indie Hut offers a perfect balance of comfort and exclusivity. From a marketing perspective, its cozy layout and peaceful vibe clearly target customers seeking a relaxed, distraction-free space. The attention to detail in ambiance and service enhances the overall experience. It’s a great spot for professionals, couples, or anyone who values privacy. The Indie Hut successfully creates an environment where guests can truly unwind and enjoy their time.
Helpful post! Anyone wanting hands-on skills should check UI UX design course online.
Thanks for sharing this guide on Best Digital Marketing Training Institute.
Very informative! Check this out: Data Science or Data Analytics
Good explanation, found this useful too: Data Science or Data Analytics
Thanks for this wonderful information, meanwhile you can check out our blog ,best helpcare center in chennai https://helpee.in/
This adds value to the topic. I saw a related guide on Data Science or Data Analytics.
Thanks for sharing! I also found this guide on Data Science vs Data Analytics useful.
Thank you for a fantastic post and a all round interesting blog. Thank you so much for sharing. best online classes for class 11 science
Loved the content you’ve shared here! For readers interested in tech and data fields, it’s also useful to explore key career topics like Data Science vs Data Analytics to understand how different data roles compare and where their skills might fit best. Thanks for the great posts!
Really enjoyed your content — it’s engaging and full of great insights! For readers interested in exploring career paths in tech and data, it’s also helpful to check out topics like Data Science vs Data Analytics to better understand how different data-related roles and skills compare. Thanks for sharing!
I enjoyed reading this, and the Figma UI UX Course caught my attention.
Thanks for sharing this post. It really helped clear my doubts about data-related careers. For a detailed breakdown, check out: Data Science vs Data Analytics.
Well explained! I’ve been enhancing my knowledge through a Best Full Stack Developer Course.
I like the perspective you shared here. I also read How to Learn Data Analytics recently.
Really enjoyed this post your writing is thoughtful, engaging, and full of insights that feel both personal and meaningful. It’s refreshing to read content that’s clear, relatable, and genuinely enjoyable. Thanks for sharing something so enriching!
For anyone also interested in growing their skills alongside great content like this, here’s a helpful Best Full Stack Developer Course worth checking out. Looking forward to your next post!
Good insights—don’t miss Best Full Stack Developer Course.
This article was really helpful and well-structured. I appreciate the effort you put into explaining things clearly. I also found this resource useful: Best Full Stack Developer Course. Thanks again for sharing!
Thanks for sharing such useful information. It’s always nice to see content that’s easy to understand. I also recommend checking this out: Best Full Stack Developer Course. Helped me a lot.
Thanks for sharing this valuable information.
How to Learn Data Analytics and Full Stack Developer Course
Very helpful content! You can also explore Digital Marketing Training in Chennai and Data Science Courses in Chennai.
Nice blog! For more learning, visit Digital Marketing Training in Chennai and Data Science Courses in Chennai.
Helpful content! I suggest learning UI from a Figma UI UX Course and coding via a Web Designing Course in Chennai.
Fantastic article! You’ve covered the topic in a clear and detailed manner.
For anyone looking to upgrade their digital marketing skills, this Social Media Marketing Course is quite helpful.
This is gold for beginners. Also see Best Web Design Course for Beginners.
This blog offers insightful perspectives on programming, software development, and real-world technical challenges, reflecting years of hands-on experience in the industry . The content feels practical and developer-focused, making it especially useful for those working with modern technologies and frameworks. It’s great to see complex topics explained in a clear and approachable way. The blog is both informative and engaging for anyone in tech. I also found this helpful resource: Best Web Design Course for Beginners. Looking forward to more valuable posts!
Nice blog! Sharing this Best Web Design Course for Beginners for beginners.
Clear and concise explanation, well done.
The blog is very easy to follow.
For anyone looking to build a career, check:
Data Science Course with Placement
Also this one is helpful:
Best IT Training Institute in Coimbatore
Valuable content, thanks for posting this.
I found it very useful and informative.
Here’s a related resource:
Data Science Course with Placement
And another good option:
Best IT Training Institute in Coimbatore
Thank you for the helpful information!
Great insights on beauty services in Chandigarh Meraki Makeup Academy truly stands out for professional training and exceptional makeup artistry skills.
Nice explanation, very easy to understand. Best Data Analytics Course in Kochi is a good resource.
Loved this post. For beginners, UI/UX Courses in Chennai is a good start.
This UI UX Design content is well organized.
It focuses on real-world applications.
A valuable learning resource.
ayodhyavaranasitourism offers a beautifully curated journey through two of India’s most spiritually rich destinations. Their seamless travel planning, knowledgeable guides, and attention to cultural detail make the experience both meaningful and hassle-free. Whether you're seeking devotion, history, or simply a peaceful getaway, their services bring out the true essence of Ayodhya and Varanasi in a memorable way.
Thanks for this valuable information! Data Science and Analytics Training
Amazing content! The Full Stack Developer Course in Coimbatore looks promising.
Great explanation! Storing the AppInsights key in web.config seems simple, but many developers overlook security implications. Have you considered using environment variables or Azure Key Vault instead? It would be interesting to compare both approaches for production environments. Satta Matka
Struggling to keep up with marketing coursework? Assignment Helpers UK offer expert assistance from qualified professionals who deliver clear and structured support. Their approach helps simplify complex concepts, making learning more manageable. With a commitment to originality and timely delivery, students can meet deadlines with ease. It’s a smart solution for improving academic performance and gaining deeper marketing insights.
Good explanation! Also interested in Data Analytics Course in Coimbatore.
Nice content for beginners.
Check Data Analytics for Beginners and Data Analytics Course in Coimbatore.
Thanks for sharing this insightful post! I especially liked the way you explained. It gave me a fresh perspective. I'll definately try to implement this in my https://menteso.com/articles/automation-reshaping-ip-management/
Thanks for sharing this insightful post! I especially liked the way you explained. It gave me a fresh perspective. I'll definately try to implement this in my https://menteso.com/articles/ai-transforming-intellectual-property-management-3/
Great content with practical learning ideas.
Useful training link: Data Science Training
The Data Science Training content is simple, practical, and beginner-friendly.
I also found the Data Science Courses in Chennai page very useful for understanding training options.
Very engaging and informative article. Anyone looking to build a strong future career can explore the Data Science and Analytics Training and this professional Digital Marketing Course in Kochi.
I appreciate the simple teaching style used in Python Programming for Beginners. It makes coding much easier for first-time learners.
For advanced technical knowledge, Data Science Courses in Chennai is a great option to explore.
Jalwa gaming account quickly and safely. Players can log in using their registered mobile number, password, or OTP to enjoy exciting games, rewards, bonuses, and daily earning opportunities. The platform offers a smooth user experience with fast access to wallet features, game history, and promotions. Website Here- https://jalwagamelogin.in.net/
Caasto’s etsy account management services have helped streamline our store operations and improve product visibility. Their team handles everything professionally, allowing us to focus on creating products while they manage growth and marketplace performance.
Excellent article with useful insights into insomnia management. Readers interested in buy Zopiclone online UK will find this guide extremely helpful.
Amazing write-up! Your explanation made a complex topic much simpler.
Reddy Anna Instant Withdrawal and Payment Methods
Weddings by neeraj kamra planned our City Palace celebration with outstanding attention to guest comfort, décor, and event flow. Their team gave us clear guidance on the Destination Wedding Cost At City Palace Udaipur while helping us select arrangements that suited our vision. Every function felt organised, elegant, and professionally managed from beginning to end.
reach us at
https://www.weddingsbyneerajkamra.com/blog/venue/destination-wedding-cost-at-city-palace-udaipur
At **PR Wires**, we believe successful SEO goes beyond rankings—it's about reaching the right audience with the right message. Combining strategic keyword research, high-quality content, and effective press release distribution helps businesses improve online visibility, build brand authority, and attract qualified traffic. We're committed to helping brands maximize their digital presence through smart content distribution and media outreach. Learn more at **https://www.prwires.com/**.
At PR Wires, we believe successful SEO goes beyond rankings—it's about reaching the right audience with the right message. Combining strategic keyword research, high-quality content, and effective press release distribution helps businesses improve online visibility, build brand authority, and attract qualified traffic. We're committed to helping brands maximize their digital presence through smart content distribution and media outreach. Learn more at https://www.prwires.com/
Very informative and easy to understand. It's great to see a training approach that focuses on practical implementation, industry best practices, and career development. Articles like this help learners make informed decisions about their professional growth. Looking forward to more quality content.
Very informative content! It's refreshing to read an article that focuses on genuine relationships and long-term compatibility instead of just quick matches. Thanks for sharing your knowledge.
ias ips matrimony grooms
Great article! I really enjoyed reading your insights—very well explained.
Thank you for sharing this valuable content.
If readers are interested in learning more about MVA physiotherapy and health , they can also explore physiotherapy options in Edmonton here:
Motor Vehicle Accident Physiotherapy Edmonton
Great article! I really liked how you explained the topic in a simple and practical way. Looking forward to reading more of your content.
Thanks for sharing this informative post. It clearly explains the importance of Guidewire Business Analyst training in today's insurance industry.
Excellent article! The information on Teamcenter and PLM is well explained and highlights why these skills are essential in today's product development industry. Thanks for sharing such valuable insights.
Excellent wedding guide! Paandora Grand Udaipur deserves recognition as the Best Wedding Hotel in Udaipur for luxury weddings and personalized service.
Visit: https://pandorahotels.co.in/paandora-grand-udaipur-events.html
Post a Comment