Xamarin forms SFListview multiselect issue - xamarin.forms

Iam using syncfusion SFListview in my xamarin forms app. I implemented multiselect of listview cell from https://help.syncfusion.com/xamarin/sflistview/selection?cs-save-lang=1&cs-lang=xaml.It works fine.But the problem iam facing is everytime we need to hold the itemcell for selection. Is it possible for multiselect that hold only for first cell and tap for all other cell?

Is it possible for multiselect that hold only for first cell and tap for all other cell?
Sure can do that.If you want multiselect items,I guess that next steps will do some tasks about multiselect items.The picture below may look like the one you want.
You can look at the content of this chapter in the share link, and the sample code it provides.
Solution One:(Generally acceptable)
If the project doesn't mind adding a control button outside, then this will be the quickest and easiest way.That is to add a ToolbarItems in the NavigationPage, use it to control whether you can click multiple selections without jumping to the next page.
Add ToolbarItems :
<ContentPage.ToolbarItems>
<ToolbarItem x:Name="ToolbarItemsButton" Text="MultipleSelect" Clicked="Edit_Clicked"/>
</ContentPage.ToolbarItems>
<sync:SfListView x:Name="listView"
SelectionGesture="Hold"
SelectionMode="Multiple"
ItemTapped="ListView_ItemTapped"
SelectionBackgroundColor="Transparent"
IsStickyHeader="True" ItemSize="70">
...
In ContentPage ,add Flag to judge SelectionMode of ListView.
int flag = 0;
private void Edit_Clicked(object sender, EventArgs e)
{
if(0 == flag)
{
listView.SelectionGesture = TouchGesture.Tap;
ToolbarItemsButton.Text = "Done";
flag = 1;
}
else
{
ToolbarItemsButton.Text = "MultipleSelect";
listView.SelectionGesture = TouchGesture.Hold;
flag = 0;
}
}
Can judge when you can switch to the next page.
private void ListView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
if(0 == flag)
{
Navigation.PushAsync(new ContentPage());
}
}
Solution Two:(Recommended)
SfListView has a method is ItemHolding.Not using another button also can exchange the SelectionMode.
Xaml code different is adding this method of SfListView.
<sync:SfListView x:Name="listView"
SelectionGesture="Hold"
SelectionMode="Multiple"
ItemTapped="ListView_ItemTapped"
SelectionBackgroundColor="Transparent"
ItemHolding="ListView_ItemHolding" // ItemHolding
IsStickyHeader="True" ItemSize="70">
When OnHolding can do something here:
private void ListView_ItemHolding(object sender, ItemHoldingEventArgs e)
{
if (0 == flag)
{
listView.SelectionGesture = TouchGesture.Tap;
ToolbarItemsButton.Text = "Done";
flag = 1;
}
else
{
listView.SelectionGesture = TouchGesture.Hold;
ToolbarItemsButton.Text = "MultipleSelect";
flag = 0;
}
}
Judge when you can switch to the next page.
private void ListView_ItemTapped(object sender, Syncfusion.ListView.XForms.ItemTappedEventArgs e)
{
if(0 == flag)
{
Navigation.PushAsync(new ContentPage());
}
}
Solution Three:(Not recommended here)
Generally, for the multiple selection of the cell of the listview, we will process the template of the custom cell, such as adding a button in the template. When clicking, the item can be marked as selected, and the UI of the item can also be customized as The style when selected.

Related

How can we change the button background color in UWP xbox app on selecting (focusing)

I want my button color to change when xbox select box is on the button. How can I achieve that? I haven't got an event on focus in Xbox UWP app.
you need a GotFocus and LostFocus events on that button you are trying to do this.
<Button x:Name="MyButton" GotFocus="ButtonGotFocus" LostFocus="ButtonLostFocus"/>
and in the code behind you can change the background color accordingly. you can also optionally check the DeviceFamily first if you want the behavior only on xbox.
private void GotFocus(object sender, object args)
{
if(AnalyticsVersionInfo.DeviceFamily == "Windows.Xbox")
{
//change the color when the button gets focus
MyButton.BackgroundColor = new SolidColorBrush(Colors.Blue);
}
}
private void LostFocus(object sender, object args)
{
if(AnalyticsVersionInfo.DeviceFamily == "Windows.Xbox")
{
//change the color when the button looses focus
MyButton.BackgroundColor = new SolidColorBrush(Colors.Green);
}
}
more on DeviceFamily property : https://learn.microsoft.com/en-us/uwp/api/windows.system.profile.analyticsversioninfo.devicefamily#Windows_System_Profile_AnalyticsVersionInfo_DeviceFamily
Update
if you want same effect on all or multiple buttons, just assign the events on every button you want the affect on like so :
<Button x:Name="MyButton" GotFocus="ButtonGotFocus" LostFocus="ButtonLostFocus"/>
<Button x:Name="MyButton2" GotFocus="ButtonGotFocus" LostFocus="ButtonLostFocus"/>
and in the backend just replce MyButton with (sender as Button)
(sender as Button).BackgroundColor = new SolidColorBrush(Colors.Green);

Interaction with parent control triggers RippleDrawable in Xamarin.Forns custom renderer

I have implemented a custom clickable label class in Xamarin.Forms along with a custom renderer, that adds a RippleDrawable as the controls Foreground. I am creating the RippleDrawable with the following code:
public static Drawable CreateRippleDrawable(Context context)
{
var typedValue = new TypedValue();
context.Theme.ResolveAttribute(Resource.Attribute.SelectableItemBackground, typedValue, true);
var rippleDrawable = context.Resources.GetDrawable(typedValue.ResourceId, context.Theme);
return rippleDrawable;
}
In my custom renderer I assign the drawable
this.Control.Foreground = DrawableHelper.CreateRippleDrawable(this.Context);
and update the ripple when the user touches the control
private void LinkLabelRenderer_Touch(object sender, TouchEventArgs e)
{
if (e.Event.Action == MotionEventActions.Down)
{
this.Pressed = true;
}
if (e.Event.Action == MotionEventActions.Cancel)
{
this.Pressed = false;
}
if (e.Event.Action == MotionEventActions.Up)
{
this.Ripple.SetHotspot(e.Event.GetX(), e.Event.GetY());
this.Pressed = false;
// raise the event of the Xamarin.Forms control
}
}
Now, whenever I click the control, the ripple will be shown, which is the expected behavior, but if I touch (tap or long-press) the parents of the control (e.g. the StackLayout, Grid or whatever layout contains the label, including their parent Layout, Page or View) the ripple animation will be triggered. Anyway, the event handler LinkLabelRenderer_Touch in not called in this case, only when the actual control is touched.
I can work around this behavior by adding an empty GestureRecognizer to the respective parent(s), but I really dislike this solution, because this is but a hack. And to make things worse it is a hack I'll always have to remember whenever I use the control.
How can I prevent the RippleDrawable being shown when the parent is touched?
Turned out I got things fundamentally wrong. Subscribing the Touch event is not the way to go. I had to make the control clickable and subscribe the Click event
this.Control.Clickable = true;
this.Click += LinkLabelRenderer_OnClick;
There is no need to handle all that RippleTouch stuff the way I did (via the Touch event) but could let android handle things for me.

How can i get xtragrid row index via repository button in gridcell?

I have buttons in xtragrid cell . i want to get row index when i clicked to repository button item. How can i get cell info or index..
I wanna show cell info at anotherp page which respository button clicked in row cell..
Can you help me ?
Thanks for advice..
To get the information about Grid HitInfo check the Hit Information Overview and Samples of Using Hit Information documentation:
private void gridView1_MouseDown(object sender, MouseEventArgs e) {
// obtaining hit info
GridHitInfo hitInfo = gridView1.CalcHitInfo(new Point(e.X, e.Y));
if (((e.Button & MouseButtons.Right) != 0) && (hitInfo.InRow) &&
(!gridView1.IsGroupRow(hitInfo.RowHandle))) {
// switching focus
gridView1.FocusedRowHandle = hitInfo.RowHandle;
// showing the custom context menu
ViewMenu menu = new ViewMenu(gridView1);
DXMenuItem menuItem = new DXMenuItem("DeleteRow",
new EventHandler(DeleteFocusedRow));
menuItem.Tag = gridView1;
menu.Items.Add(menuItem);
menu.Show(hitInfo.HitPoint);
}
}
Check this:
private void repositoryItemButtonEdit_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
{
myGridView.DeleteRow(myGridView.FocusedRowHandle); /// you can get focusedRowHandle here
}
Reference:
Winforms XtraGrid Delete Row Button
Delete button on each row of grid - how do we prevent the user from typing text in the new column with the delete button
Edit:
Refere this Devexpres thread: Cannot get the rowhandle to delete a row using RepositoryItemButtonEdit

How to hide column in some nodes in Devexpress ASPxTreeList control?

I'm using ASPxTrrList control from Devexpress and I want to hide delete button (or any column) in some nodes depending on specific condition.
I tried (HtmlRowPrepared) event but I couldn't locate the column I want, it looks like its index changes depending on the node level.
Any way to do this ?
I solved it using this code:
protected void MyTree_HtmlCommandCellPrepared(object sender, TreeListHtmlCommandCellEventArgs e)
{
var node = MyTree.GetAllNodes().SingleOrDefault(k => k.Key == e.NodeKey);
if (node != null && anyCondition)
e.Cell.Visible = false;
}
I'm using only one command button, so I didn't try to hide specific button.

Silverlight toolkit : How to read seleted value of a data point on Bubble Chart

I have created a Bubble chart using silverlight tookit as follows :
<charting:Chart Title="Bubble Chart"
LegendTitle="Legend"
Name="chart1" Margin="0,0,0,42"
HorizontalAlignment="Left" Width="568">
<charting:Chart.Series>
<charting:BubbleSeries Title="Pollutant A" IsSelectionEnabled="True"
ItemsSource="{Binding Pollution}"
IndependentValuePath="AQI"
DependentValuePath="Level"
SelectionChanged="ChangeSomething"
SizeValuePath="size1" >
</charting:BubbleSeries>
</charting:Chart>
And my xaml.cs defines the handler like this :
private void ChangeSomething(object sender, SelectionChangedEventArgs e){
Text1.text="selection changed"
// Here I want to show the value of the bubble selected
}
Can someone Please tell me How to do that ? thanks :)
The SelectionChangedEventArgs parameter will contain a property called AddedItems, this is a list of the items for the ItemsSource that have been added to the selected items during this change. Most of the time there is only one, its the item that was just selected.
For the sake of example I'll event a type name for the objects returned by your Pollution property in your model. I'll give the type name PollutionSample (of course I'm just guessing here).
So you would access the selected PollutionSample like this:-
private void ChangeSomething(object sender, SelectionChangedEventArgs e)
{
if (e.AddedItems.Count > 0)
{
PollutionSample ps = e.AddedItems[0] as PollutionSample;
if (ps != null)
{
// Do something with sample
}
}
}

Resources