When i click the event on outside of listview switch button or inside of listview switch button, it will...
up vote
0
down vote
favorite
I am using xamarin forms listview.
I am using switch control on both listview and outside of listview:
When i click the event on outside of listview switch button or inside of listview switch button, it will affect bothin event class.
How to avoid these issue.
My code for xaml file is below:
<Label Margin="0,0,10,0" Text="Select All" TextColor="Black" FontSize="Medium" HorizontalOptions="End" VerticalOptions="Center"></Label>
<Switch Margin="0,0,10,0" x:Name="SelectToggled" HorizontalOptions="End" VerticalOptions="Center" Toggled="Switch_Toggled" ></Switch>
<ListView x:Name="LocationListView" HasUnevenRows="True" SeparatorVisibility="None" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="0,0,0,0" BackgroundColor="{Binding backgroundColor}" HeightRequest="47" RowSpacing="0" HorizontalOptions="FillAndExpand" Padding="20,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding CountryName}" HorizontalOptions="Start" VerticalOptions="Center" TextColor="Black" FontFamily="Roboto" FontSize="Medium"></Label>
<Switch Grid.Row="0" Grid.Column="1" HorizontalOptions="CenterAndExpand" Toggled="SwitchList_Toggled" VerticalOptions="CenterAndExpand" IsToggled="{Binding IsToggle,Mode=TwoWay}"></Switch>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My code for xaml.cs is:
public MarketLanding()
{
InitializeComponent();
ObservableCollection<Country> countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India" });
countrylist.Add(new Country { CountryName = "America" });
countrylist.Add(new Country { CountryName = "England" });
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
}
Anyone please help me to sort out this issue.
xamarin.forms xamarin.forms.listview
add a comment |
up vote
0
down vote
favorite
I am using xamarin forms listview.
I am using switch control on both listview and outside of listview:
When i click the event on outside of listview switch button or inside of listview switch button, it will affect bothin event class.
How to avoid these issue.
My code for xaml file is below:
<Label Margin="0,0,10,0" Text="Select All" TextColor="Black" FontSize="Medium" HorizontalOptions="End" VerticalOptions="Center"></Label>
<Switch Margin="0,0,10,0" x:Name="SelectToggled" HorizontalOptions="End" VerticalOptions="Center" Toggled="Switch_Toggled" ></Switch>
<ListView x:Name="LocationListView" HasUnevenRows="True" SeparatorVisibility="None" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="0,0,0,0" BackgroundColor="{Binding backgroundColor}" HeightRequest="47" RowSpacing="0" HorizontalOptions="FillAndExpand" Padding="20,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding CountryName}" HorizontalOptions="Start" VerticalOptions="Center" TextColor="Black" FontFamily="Roboto" FontSize="Medium"></Label>
<Switch Grid.Row="0" Grid.Column="1" HorizontalOptions="CenterAndExpand" Toggled="SwitchList_Toggled" VerticalOptions="CenterAndExpand" IsToggled="{Binding IsToggle,Mode=TwoWay}"></Switch>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My code for xaml.cs is:
public MarketLanding()
{
InitializeComponent();
ObservableCollection<Country> countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India" });
countrylist.Add(new Country { CountryName = "America" });
countrylist.Add(new Country { CountryName = "England" });
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
}
Anyone please help me to sort out this issue.
xamarin.forms xamarin.forms.listview
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I am using xamarin forms listview.
I am using switch control on both listview and outside of listview:
When i click the event on outside of listview switch button or inside of listview switch button, it will affect bothin event class.
How to avoid these issue.
My code for xaml file is below:
<Label Margin="0,0,10,0" Text="Select All" TextColor="Black" FontSize="Medium" HorizontalOptions="End" VerticalOptions="Center"></Label>
<Switch Margin="0,0,10,0" x:Name="SelectToggled" HorizontalOptions="End" VerticalOptions="Center" Toggled="Switch_Toggled" ></Switch>
<ListView x:Name="LocationListView" HasUnevenRows="True" SeparatorVisibility="None" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="0,0,0,0" BackgroundColor="{Binding backgroundColor}" HeightRequest="47" RowSpacing="0" HorizontalOptions="FillAndExpand" Padding="20,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding CountryName}" HorizontalOptions="Start" VerticalOptions="Center" TextColor="Black" FontFamily="Roboto" FontSize="Medium"></Label>
<Switch Grid.Row="0" Grid.Column="1" HorizontalOptions="CenterAndExpand" Toggled="SwitchList_Toggled" VerticalOptions="CenterAndExpand" IsToggled="{Binding IsToggle,Mode=TwoWay}"></Switch>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My code for xaml.cs is:
public MarketLanding()
{
InitializeComponent();
ObservableCollection<Country> countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India" });
countrylist.Add(new Country { CountryName = "America" });
countrylist.Add(new Country { CountryName = "England" });
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
}
Anyone please help me to sort out this issue.
xamarin.forms xamarin.forms.listview
I am using xamarin forms listview.
I am using switch control on both listview and outside of listview:
When i click the event on outside of listview switch button or inside of listview switch button, it will affect bothin event class.
How to avoid these issue.
My code for xaml file is below:
<Label Margin="0,0,10,0" Text="Select All" TextColor="Black" FontSize="Medium" HorizontalOptions="End" VerticalOptions="Center"></Label>
<Switch Margin="0,0,10,0" x:Name="SelectToggled" HorizontalOptions="End" VerticalOptions="Center" Toggled="Switch_Toggled" ></Switch>
<ListView x:Name="LocationListView" HasUnevenRows="True" SeparatorVisibility="None" VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid Margin="0,0,0,0" BackgroundColor="{Binding backgroundColor}" HeightRequest="47" RowSpacing="0" HorizontalOptions="FillAndExpand" Padding="20,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="20*"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0" Text="{Binding CountryName}" HorizontalOptions="Start" VerticalOptions="Center" TextColor="Black" FontFamily="Roboto" FontSize="Medium"></Label>
<Switch Grid.Row="0" Grid.Column="1" HorizontalOptions="CenterAndExpand" Toggled="SwitchList_Toggled" VerticalOptions="CenterAndExpand" IsToggled="{Binding IsToggle,Mode=TwoWay}"></Switch>
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My code for xaml.cs is:
public MarketLanding()
{
InitializeComponent();
ObservableCollection<Country> countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India" });
countrylist.Add(new Country { CountryName = "America" });
countrylist.Add(new Country { CountryName = "England" });
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
}
Anyone please help me to sort out this issue.
xamarin.forms xamarin.forms.listview
xamarin.forms xamarin.forms.listview
asked Nov 7 at 12:21
Arun manthiram
608
608
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
You can foreach through CountryList, I do one sample that you can take a look:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="Test1.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Test1">
<StackLayout>
<Label
Margin="0,0,10,0"
FontSize="Medium"
HorizontalOptions="End"
Text="Select All"
TextColor="White"
VerticalOptions="Center" />
<Switch
x:Name="SelectToggled"
Margin="0,0,10,0"
BackgroundColor="BlueViolet"
HorizontalOptions="End"
Toggled="Switch_Toggled"
VerticalOptions="Center" />
<ListView
x:Name="LocationListView"
BackgroundColor="AliceBlue"
HasUnevenRows="True"
SeparatorVisibility="None"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid
Margin="0,0,0,0"
Padding="20,0,0,0"
BackgroundColor="{Binding backgroundColor}"
HeightRequest="47"
HorizontalOptions="FillAndExpand"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
FontFamily="Roboto"
FontSize="Medium"
HorizontalOptions="Start"
Text="{Binding CountryName}"
TextColor="Black"
VerticalOptions="Center" />
<Switch
x:Name="switch1"
Grid.Row="0"
Grid.Column="1"
HorizontalOptions="CenterAndExpand"
IsToggled="{Binding IsToggle, Mode=TwoWay}"
Toggled="SwitchList_Toggled"
VerticalOptions="CenterAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public ObservableCollection<Country> countrylist { get; set; }
public MainPage()
{
InitializeComponent();
countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India",IsToggle=false });
countrylist.Add(new Country { CountryName = "America" ,IsToggle=true});
countrylist.Add(new Country { CountryName = "England" ,IsToggle=false});
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" outside switch clicked");
if(SelectToggled.IsToggled)
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = true;
}
}
else
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = false;
}
}
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" inside switch clicked");
}
public class Country:INotifyPropertyChanged
{
private string _CountryName;
public string CountryName
{
get { return _CountryName; }
set
{
_CountryName = value;
RaisePropertyChanged("CountryName");
}
}
private Color _backgroundColor;
public Color backgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
RaisePropertyChanged("backgroundColor");
}
}
private bool _IsToggle;
public bool IsToggle
{
get { return _IsToggle; }
set
{
_IsToggle = value;
RaisePropertyChanged("IsToggle");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if(handler!=null)
{
handler(this,new PropertyChangedEventArgs(propertyName));
}
}
}
Hi Cherry, Thank your reply. But I need the following...
– Arun manthiram
Nov 9 at 13:39
When i Switched On the "Outside switch control", all "inside switch controls" should be switched On. When I Switched Off the "Outside switch control", all "inside switch controls" should be switched Off. When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On.
– Arun manthiram
Nov 9 at 13:39
@Arun, For When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, I think it is not unreasonable, because When you switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, then all "inside switch controls" should be switched On. . It is meaningless.
– Cherry Bu
Nov 12 at 7:21
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
You can foreach through CountryList, I do one sample that you can take a look:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="Test1.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Test1">
<StackLayout>
<Label
Margin="0,0,10,0"
FontSize="Medium"
HorizontalOptions="End"
Text="Select All"
TextColor="White"
VerticalOptions="Center" />
<Switch
x:Name="SelectToggled"
Margin="0,0,10,0"
BackgroundColor="BlueViolet"
HorizontalOptions="End"
Toggled="Switch_Toggled"
VerticalOptions="Center" />
<ListView
x:Name="LocationListView"
BackgroundColor="AliceBlue"
HasUnevenRows="True"
SeparatorVisibility="None"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid
Margin="0,0,0,0"
Padding="20,0,0,0"
BackgroundColor="{Binding backgroundColor}"
HeightRequest="47"
HorizontalOptions="FillAndExpand"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
FontFamily="Roboto"
FontSize="Medium"
HorizontalOptions="Start"
Text="{Binding CountryName}"
TextColor="Black"
VerticalOptions="Center" />
<Switch
x:Name="switch1"
Grid.Row="0"
Grid.Column="1"
HorizontalOptions="CenterAndExpand"
IsToggled="{Binding IsToggle, Mode=TwoWay}"
Toggled="SwitchList_Toggled"
VerticalOptions="CenterAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public ObservableCollection<Country> countrylist { get; set; }
public MainPage()
{
InitializeComponent();
countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India",IsToggle=false });
countrylist.Add(new Country { CountryName = "America" ,IsToggle=true});
countrylist.Add(new Country { CountryName = "England" ,IsToggle=false});
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" outside switch clicked");
if(SelectToggled.IsToggled)
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = true;
}
}
else
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = false;
}
}
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" inside switch clicked");
}
public class Country:INotifyPropertyChanged
{
private string _CountryName;
public string CountryName
{
get { return _CountryName; }
set
{
_CountryName = value;
RaisePropertyChanged("CountryName");
}
}
private Color _backgroundColor;
public Color backgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
RaisePropertyChanged("backgroundColor");
}
}
private bool _IsToggle;
public bool IsToggle
{
get { return _IsToggle; }
set
{
_IsToggle = value;
RaisePropertyChanged("IsToggle");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if(handler!=null)
{
handler(this,new PropertyChangedEventArgs(propertyName));
}
}
}
Hi Cherry, Thank your reply. But I need the following...
– Arun manthiram
Nov 9 at 13:39
When i Switched On the "Outside switch control", all "inside switch controls" should be switched On. When I Switched Off the "Outside switch control", all "inside switch controls" should be switched Off. When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On.
– Arun manthiram
Nov 9 at 13:39
@Arun, For When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, I think it is not unreasonable, because When you switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, then all "inside switch controls" should be switched On. . It is meaningless.
– Cherry Bu
Nov 12 at 7:21
add a comment |
up vote
0
down vote
You can foreach through CountryList, I do one sample that you can take a look:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="Test1.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Test1">
<StackLayout>
<Label
Margin="0,0,10,0"
FontSize="Medium"
HorizontalOptions="End"
Text="Select All"
TextColor="White"
VerticalOptions="Center" />
<Switch
x:Name="SelectToggled"
Margin="0,0,10,0"
BackgroundColor="BlueViolet"
HorizontalOptions="End"
Toggled="Switch_Toggled"
VerticalOptions="Center" />
<ListView
x:Name="LocationListView"
BackgroundColor="AliceBlue"
HasUnevenRows="True"
SeparatorVisibility="None"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid
Margin="0,0,0,0"
Padding="20,0,0,0"
BackgroundColor="{Binding backgroundColor}"
HeightRequest="47"
HorizontalOptions="FillAndExpand"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
FontFamily="Roboto"
FontSize="Medium"
HorizontalOptions="Start"
Text="{Binding CountryName}"
TextColor="Black"
VerticalOptions="Center" />
<Switch
x:Name="switch1"
Grid.Row="0"
Grid.Column="1"
HorizontalOptions="CenterAndExpand"
IsToggled="{Binding IsToggle, Mode=TwoWay}"
Toggled="SwitchList_Toggled"
VerticalOptions="CenterAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public ObservableCollection<Country> countrylist { get; set; }
public MainPage()
{
InitializeComponent();
countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India",IsToggle=false });
countrylist.Add(new Country { CountryName = "America" ,IsToggle=true});
countrylist.Add(new Country { CountryName = "England" ,IsToggle=false});
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" outside switch clicked");
if(SelectToggled.IsToggled)
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = true;
}
}
else
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = false;
}
}
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" inside switch clicked");
}
public class Country:INotifyPropertyChanged
{
private string _CountryName;
public string CountryName
{
get { return _CountryName; }
set
{
_CountryName = value;
RaisePropertyChanged("CountryName");
}
}
private Color _backgroundColor;
public Color backgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
RaisePropertyChanged("backgroundColor");
}
}
private bool _IsToggle;
public bool IsToggle
{
get { return _IsToggle; }
set
{
_IsToggle = value;
RaisePropertyChanged("IsToggle");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if(handler!=null)
{
handler(this,new PropertyChangedEventArgs(propertyName));
}
}
}
Hi Cherry, Thank your reply. But I need the following...
– Arun manthiram
Nov 9 at 13:39
When i Switched On the "Outside switch control", all "inside switch controls" should be switched On. When I Switched Off the "Outside switch control", all "inside switch controls" should be switched Off. When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On.
– Arun manthiram
Nov 9 at 13:39
@Arun, For When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, I think it is not unreasonable, because When you switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, then all "inside switch controls" should be switched On. . It is meaningless.
– Cherry Bu
Nov 12 at 7:21
add a comment |
up vote
0
down vote
up vote
0
down vote
You can foreach through CountryList, I do one sample that you can take a look:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="Test1.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Test1">
<StackLayout>
<Label
Margin="0,0,10,0"
FontSize="Medium"
HorizontalOptions="End"
Text="Select All"
TextColor="White"
VerticalOptions="Center" />
<Switch
x:Name="SelectToggled"
Margin="0,0,10,0"
BackgroundColor="BlueViolet"
HorizontalOptions="End"
Toggled="Switch_Toggled"
VerticalOptions="Center" />
<ListView
x:Name="LocationListView"
BackgroundColor="AliceBlue"
HasUnevenRows="True"
SeparatorVisibility="None"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid
Margin="0,0,0,0"
Padding="20,0,0,0"
BackgroundColor="{Binding backgroundColor}"
HeightRequest="47"
HorizontalOptions="FillAndExpand"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
FontFamily="Roboto"
FontSize="Medium"
HorizontalOptions="Start"
Text="{Binding CountryName}"
TextColor="Black"
VerticalOptions="Center" />
<Switch
x:Name="switch1"
Grid.Row="0"
Grid.Column="1"
HorizontalOptions="CenterAndExpand"
IsToggled="{Binding IsToggle, Mode=TwoWay}"
Toggled="SwitchList_Toggled"
VerticalOptions="CenterAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public ObservableCollection<Country> countrylist { get; set; }
public MainPage()
{
InitializeComponent();
countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India",IsToggle=false });
countrylist.Add(new Country { CountryName = "America" ,IsToggle=true});
countrylist.Add(new Country { CountryName = "England" ,IsToggle=false});
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" outside switch clicked");
if(SelectToggled.IsToggled)
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = true;
}
}
else
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = false;
}
}
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" inside switch clicked");
}
public class Country:INotifyPropertyChanged
{
private string _CountryName;
public string CountryName
{
get { return _CountryName; }
set
{
_CountryName = value;
RaisePropertyChanged("CountryName");
}
}
private Color _backgroundColor;
public Color backgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
RaisePropertyChanged("backgroundColor");
}
}
private bool _IsToggle;
public bool IsToggle
{
get { return _IsToggle; }
set
{
_IsToggle = value;
RaisePropertyChanged("IsToggle");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if(handler!=null)
{
handler(this,new PropertyChangedEventArgs(propertyName));
}
}
}
You can foreach through CountryList, I do one sample that you can take a look:
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="Test1.MainPage"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Test1">
<StackLayout>
<Label
Margin="0,0,10,0"
FontSize="Medium"
HorizontalOptions="End"
Text="Select All"
TextColor="White"
VerticalOptions="Center" />
<Switch
x:Name="SelectToggled"
Margin="0,0,10,0"
BackgroundColor="BlueViolet"
HorizontalOptions="End"
Toggled="Switch_Toggled"
VerticalOptions="Center" />
<ListView
x:Name="LocationListView"
BackgroundColor="AliceBlue"
HasUnevenRows="True"
SeparatorVisibility="None"
VerticalOptions="FillAndExpand">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<Grid
Margin="0,0,0,0"
Padding="20,0,0,0"
BackgroundColor="{Binding backgroundColor}"
HeightRequest="47"
HorizontalOptions="FillAndExpand"
RowSpacing="0">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*" />
<ColumnDefinition Width="20*" />
</Grid.ColumnDefinitions>
<Label
Grid.Row="0"
Grid.Column="0"
FontFamily="Roboto"
FontSize="Medium"
HorizontalOptions="Start"
Text="{Binding CountryName}"
TextColor="Black"
VerticalOptions="Center" />
<Switch
x:Name="switch1"
Grid.Row="0"
Grid.Column="1"
HorizontalOptions="CenterAndExpand"
IsToggled="{Binding IsToggle, Mode=TwoWay}"
Toggled="SwitchList_Toggled"
VerticalOptions="CenterAndExpand" />
</Grid>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</StackLayout>
public ObservableCollection<Country> countrylist { get; set; }
public MainPage()
{
InitializeComponent();
countrylist = new ObservableCollection<Country>();
countrylist.Add(new Country { CountryName = "India",IsToggle=false });
countrylist.Add(new Country { CountryName = "America" ,IsToggle=true});
countrylist.Add(new Country { CountryName = "England" ,IsToggle=false});
for (int i = 0; i < countrylist.Count; i++)
{
if (i % 2 == 0)
{
countrylist[i].backgroundColor = Color.LightGray;
}
else
{
countrylist[i].backgroundColor = Color.White;
}
}
LocationListView.ItemsSource = countrylist;
}
private void Switch_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" outside switch clicked");
if(SelectToggled.IsToggled)
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = true;
}
}
else
{
for (Int32 i = 0; i < countrylist.Count; i++)
{
countrylist[i].IsToggle = false;
}
}
}
private void SwitchList_Toggled(object sender, ToggledEventArgs e)
{
Console.WriteLine(" inside switch clicked");
}
public class Country:INotifyPropertyChanged
{
private string _CountryName;
public string CountryName
{
get { return _CountryName; }
set
{
_CountryName = value;
RaisePropertyChanged("CountryName");
}
}
private Color _backgroundColor;
public Color backgroundColor
{
get { return _backgroundColor; }
set
{
_backgroundColor = value;
RaisePropertyChanged("backgroundColor");
}
}
private bool _IsToggle;
public bool IsToggle
{
get { return _IsToggle; }
set
{
_IsToggle = value;
RaisePropertyChanged("IsToggle");
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void RaisePropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = PropertyChanged;
if(handler!=null)
{
handler(this,new PropertyChangedEventArgs(propertyName));
}
}
}
answered Nov 8 at 4:44
Cherry Bu
84628
84628
Hi Cherry, Thank your reply. But I need the following...
– Arun manthiram
Nov 9 at 13:39
When i Switched On the "Outside switch control", all "inside switch controls" should be switched On. When I Switched Off the "Outside switch control", all "inside switch controls" should be switched Off. When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On.
– Arun manthiram
Nov 9 at 13:39
@Arun, For When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, I think it is not unreasonable, because When you switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, then all "inside switch controls" should be switched On. . It is meaningless.
– Cherry Bu
Nov 12 at 7:21
add a comment |
Hi Cherry, Thank your reply. But I need the following...
– Arun manthiram
Nov 9 at 13:39
When i Switched On the "Outside switch control", all "inside switch controls" should be switched On. When I Switched Off the "Outside switch control", all "inside switch controls" should be switched Off. When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On.
– Arun manthiram
Nov 9 at 13:39
@Arun, For When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, I think it is not unreasonable, because When you switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, then all "inside switch controls" should be switched On. . It is meaningless.
– Cherry Bu
Nov 12 at 7:21
Hi Cherry, Thank your reply. But I need the following...
– Arun manthiram
Nov 9 at 13:39
Hi Cherry, Thank your reply. But I need the following...
– Arun manthiram
Nov 9 at 13:39
When i Switched On the "Outside switch control", all "inside switch controls" should be switched On. When I Switched Off the "Outside switch control", all "inside switch controls" should be switched Off. When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On.
– Arun manthiram
Nov 9 at 13:39
When i Switched On the "Outside switch control", all "inside switch controls" should be switched On. When I Switched Off the "Outside switch control", all "inside switch controls" should be switched Off. When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On.
– Arun manthiram
Nov 9 at 13:39
@Arun, For When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, I think it is not unreasonable, because When you switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, then all "inside switch controls" should be switched On. . It is meaningless.
– Cherry Bu
Nov 12 at 7:21
@Arun, For When I switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, I think it is not unreasonable, because When you switched Off/On any switch control in "inside switch Control",then the "outside switch control" should be automatically switched Off/On, then all "inside switch controls" should be switched On. . It is meaningless.
– Cherry Bu
Nov 12 at 7:21
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53189391%2fwhen-i-click-the-event-on-outside-of-listview-switch-button-or-inside-of-listvie%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown