|
<ContentPage.BindingContext>
<local:ViewModel/>
</ContentPage.BindingContext>
<ContentPage.Content>
<StackLayout>
<buttons:SfChipGroup x:Name="TextColor" Type="Action" Command="{Binding ChipCommand}" Margin="18,0,18,0" SelectionIndicatorColor="#9900CC" >
<buttons:SfChipGroup.Items>
<buttons:SfChip BackgroundColor="#EB5757" HeightRequest="50" WidthRequest="50"/>
<buttons:SfChip BackgroundColor="#F2994A" HeightRequest="50" WidthRequest="50"/>
<buttons:SfChip BackgroundColor="#F2C94C" HeightRequest="50" WidthRequest="50"/>
<buttons:SfChip BackgroundColor="#219653" HeightRequest="50" WidthRequest="50"/>
<buttons:SfChip BackgroundColor="#2F80ED" HeightRequest="50" WidthRequest="50"/>
<buttons:SfChip BackgroundColor="#9B51E0" HeightRequest="50" WidthRequest="50"/>
<buttons:SfChip BackgroundColor="#333333" HeightRequest="50" WidthRequest="50"/>
<buttons:SfChip BackgroundColor="#FFFFFF" HeightRequest="50" WidthRequest="50"/>
</buttons:SfChipGroup.Items>
</buttons:SfChipGroup>
<BoxView Margin="0,30,0,0" Color="{Binding SelectedColor}" HeightRequest="40" WidthRequest="40" HorizontalOptions="Center" VerticalOptions="Center"/>
</StackLayout>
</ContentPage.Content> |
|
public class ViewModel :INotifyPropertyChanged
{
private Color selectedColor;
public event PropertyChangedEventHandler PropertyChanged;
public Color SelectedColor
{
get { return selectedColor; }
set
{
selectedColor = value;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("SelectedColor"));
}
}
public Command ChipCommand { get; set; }
public ViewModel()
{
ChipCommand = new Command<object>(ChipCommandEx);
}
private void ChipCommandEx(object obj)
{
SelectedColor = (obj as SfChip).BackgroundColor;
}
} |