This section describes adding the C1ToggleButton control to your portable or shared application and changing color of the control on the basis of change in state of the control.
Complete the following steps to change color of the control on changing its state.
The following image shows the change in color of the control on changing its state.
XAML |
Copy Code
|
---|---|
xmlns:c1tog="clr-namespace:C1.Xamarin.Forms.Core;assembly=C1.Xamarin.Forms.Core" |
XAML |
Copy Code
|
---|---|
<c1tog:C1ToggleButton x:Name="Toggle" BackgroundColor="Green" HeightRequest="50" WidthRequest="100" HorizontalOptions="Center" VerticalOptions="Center" CheckedText="Checked" UncheckedText="Unchecked"/> |
C# |
Copy Code
|
---|---|
private void Toggle_Checked(object sender, EventArgs e) { if(Toggle.IsChecked == true) { Toggle.BackgroundColor = Color.Green; } else if(Toggle.IsChecked == false) { Toggle.BackgroundColor = Color.Red; } } |
C# |
Copy Code
|
---|---|
Toggle.Checked += Toggle_Checked; |
C# |
Copy Code
|
---|---|
public App() { // The root page of your application MainPage = new MainPage(); } |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Core.Platform.iOS.C1CoreRenderer.Init(); |
C# |
Copy Code
|
---|---|
C1.Xamarin.Forms.Core.Platform.UWP.C1CoreRenderer.Init(); |
(Optional) In case you compile your UWP application in Release mode, you need to explicitly add the following code to the OnLaunched method in your App.xaml.cs to include the correct assemblies with your application.
C# |
Copy Code
|
---|---|
var assembliesToInclude = new List<Assembly>();assembliesToInclude.Add(typeof(C1.Xamarin.Forms.Core.Platform.UWP.C1CoreRenderer).GetTypeInfo().Assembly);Xamarin.Forms.Forms.Init(e, assembliesToInclude); |