1
\$\begingroup\$

I wanted to know is this the best way to handle a SegmentedControl using the e.NewValue? Base on the selected segment I hide and select different data?

XAML

<telerikInput:RadSegmentedControl.ItemsSource>
                            <x:Array Type="{x:Type x:String}">
                                <x:String>Option One</x:String>
                                <x:String>Option Two</x:String> 
                                <x:String>Favorites</x:String>
                            </x:Array>
</telerikInput:RadSegmentedControl.ItemsSource>

c#

private void Show_SelectionChanged(object sender, ValueChangedEventArgs<int> e)
        {
            if (HomeListView.ItemsSource != null)
            {
                TilesViewModel gtvm = new TilesViewModel();

                switch (e.NewValue)
                {

                    case 0:
                        var selectoneItems = gtvm.ListItems.Where(x => x.IsProfessional).ToList();
                        HomeGuidelineListView.ItemsSource = selectoneItems ;
                        selecttwoTitle.IsVisible = false;
                        selectoneTitle.IsVisible = true;
                        FavOptionsGrid.IsVisible = false;
                        HomeOptionsGrid.IsVisible = true;
                        NoFavsMessage.IsVisible = false;
                        break;
                    case 1:
                        var selecttwoItems = gtvm.ListItems.Where(x => x.IsProfessional == false).ToList();
                        selecttwoTitle.IsVisible = true;
                        selectoneTitle.IsVisible = false;
                        FavOptionsGrid.IsVisible = false;
                        HomeOptionsGrid.IsVisible = true;
                        NoFavsMessage.IsVisible = false;
                        break;
                    case 2:
                         var favItems = gtvm.GuidelineListItems.Where(x => x.IsFavorite).ToList();
                         HomeGuidelineListView.ItemsSource = favItems;
                         HomeOptionsGrid.IsVisible = false;
                         FavOptionsGrid.IsVisible = true;
                        break;
                }
            }
        }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.