///<summary> ///GetsorsetstheSuppliesListListofoptionsforretailerssupplies. ///summary> publicObservableCollection<RetailerSuppiles>SuppliesList { get=>supplies; set { SetProperty(refsupplies,value,nameof(SuppliesList)); OnPropertyChanged(nameof(SuppliesList)); } } //Createanewlistofitemstoselectfromthecombobox ///<summary> ///privatestorageSelected ///summary> privateObservableCollection<RetailerSuppiles>selected; ///<summary> ///GetsorsetsthevalueforSelected ///summary> publicObservableCollection<RetailerSuppiles>Selected { get=>selected; set { SetProperty(refselected,value,nameof(Selected)); OnPropertyChanged(nameof(Selected)); } } ///<summary> ///Populatethesupplyoptionsfortheretailers. ///summary> privatevoidBuildSupplyOptions() { SuppliesList=newObservableCollection<RetailerSuppiles> { newRetailerSuppiles{Name="Archery",Image=ArcheryIcon}, newRetailerSuppiles{Name="Camping",Image=TentIcon}, newRetailerSuppiles{Name="Gear",Image=SwissArmyIcon}, newRetailerSuppiles{Name="Other",Image=AccessoryIcon}, }; }
///<summary> ///Eventhandlerforchangingvalueinaproperty. ///summary> ///<paramname="propertyName">Nameofthepropertybeingchanged.param> protectedvoidOnPropertyChanged([CallerMemberName]stringpropertyName="") { Logger.Trace($"OnPropertyChanged({propertyName})for{PropertyChanged?.ToString()}."); varchanged=PropertyChanged; if(changed==null) { Logger.Trace($"OnPropertyChanged({propertyName}):changed==null,returning."); return; } Logger.Trace($"OnPropertyChanged({propertyName}):Invokingchangedaction."); changed.Invoke(this,newPropertyChangedEventArgs(propertyName)); } ///<summary> ///Setsthevalueofaproperty. ///summary> ///<typeparamname="T">Nameoftypeofproperty.typeparam> ///<paramname="backingStore">Oldvalue.param> ///<paramname="value">Newvalue.param> ///<paramname="propertyName">Nameofpropertybeingchanged.param> ///<paramname="onChanged">eventhandlerforchange.param> ///<returns>Resultas<seecref="bool"/>.returns> #pragmawarningdisableS3343//Callerinformationparametersshouldcomeattheendoftheparameterlist protectedboolSetProperty<T>(refTbackingStore,Tvalue,[CallerMemberName]stringpropertyName="",ActiononChanged=null) #pragmawarningrestoreS3343//Callerinformationparametersshouldcomeattheendoftheparameterlist { Logger.Trace($"SetProperty<{typeof(T)}>:bs<{typeof(T)}>{backingStore}.v<{typeof(T)}>{value}.prop'{propertyName}'."); if(EqualityComparer<T>.Default.Equals(backingStore,value)) { returnfalse; } backingStore=value; onChanged?.Invoke(); OnPropertyChanged(propertyName); returntrue; }
<combobox:SfComboBox x:Name="Supplies" DataSource="{BindingPath=RetailerSupplies,Mode=TwoWay}" EnableAutoSize="True" IndicatorTextColor="{StaticResourceKey=cTblSelected}" IsEditableMode="False" IsSelectedItemsVisibleInDropDown="False" MultiSelectMode="Token" TextSize="12" TokensWrapMode="Wrap" WidthRequest="200"> <combobox:SfComboBox.TokenSettings> <combobox:TokenSettings BackgroundColor="{StaticResourceKey=cFrameBGColor}" CornerRadius="5" DeleteButtonColor="{StaticResourceKey=cFrameBorderColor}" FontSize="13" TextColor="{StaticResourceKey=cAltTextColor}"/> combobox:SfComboBox.TokenSettings> <combobox:SfComboBox.DropDownButtonSettings> <combobox:DropDownButtonSettings BackgroundColor="{StaticResourceKey=cFrameBGColor}" FontColor="{StaticResourceKey=primary-title-color}" HighlightedBackgroundColor="{StaticResourceKey=cHilightColor}"/> combobox:SfComboBox.DropDownButtonSettings> combobox:SfComboBox>
///<summary> ///TheRecoverOptions ///summary> privatevoidRecoverOptions() { //Recoverthelistfromthedatabaseandmakeitalistofstrings varsupplieslist=newList<string>(viewModel.MyRetailer.Supplies.Split(',')); //Iteratethroughthearrayofstrings,andbuildthelistofselecteditemsforthe //combobox. foreach(stringsinsupplieslist) { RetailerSuppilessup=viewModel.SuppliesList.FirstOrDefault(x=>x.Name.Equals(s,StringComparison.OrdinalIgnoreCase)); viewModel.Selected.Add(sup); } Supplies.SelectedItem=viewModel.Selected; Supplies.FilteredItems=viewModel.Selected; }
<comboBox:SfComboBox
x:Name="comboBox"
AllowFiltering="True"
DataSource="{Binding EmployeeCollection}"
DisplayMemberPath="Name"
EnableAutoSize="True"
IsEditableMode="True"
IsSelectedItemsVisibleInDropDown="False"
MultiSelectMode="Token"
TokensWrapMode="Wrap" /> |