Comments (4)
This is not a bug, but a ListView behavior in Xamarin.Forms.
When you bind data inside a ListView, the framework bind that data to the type of ItemsSource, and the "GetMenuCommand" does not exists in your Item Source class (or whatever).
You need to do some modifications in your ClickedCommand to make it work.
XAML
You need to define some name to your ListView with x:Name=""
and change the ClickedCommand
to be like I show below.
<ListView ItemsSource="{Binding MyListDataSource}" HasUnevenRows="True" x:Name="MyListView">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<flex:FlexButton
VerticalOptions="CenterAndExpand"
Icon="location.png"
WidthRequest="60"
HeightRequest="60"
ForegroundColor="White"
HighlightForegroundColor="#49516F"
BackgroundColor="#6279B8"
HighlightBackgroundColor="#8EA4D2"
ClickedCommand="{Binding Path=BindingContext.MyCommand, Source={x:Reference MyListView}}"
ClickedCommandParameter="{Binding .}" />
ViewModel
- Your data source will be like
public ObservableCollection<MyObject> MyListDataSource { get; }
- You need a ICommand like
public ICommand MyCommand { get; }
- A instance for your command:
MyCommand = new Command<MyObject>(MyCommandAction);
- And your implementation of an action like you want. 👍
private async void MyCommandAction(MyObject myObject)
{
// Do what you want here
}
This works for me. 😄
PS: English is not my first language, so I feel sorry about some mispelling. 😅
from flexbutton.
Oh that's interesting. I've never seen a FlexButton in a ListView so this error never came up, but I will give it a play.
from flexbutton.
+1
from flexbutton.
Testing on Android and iOS can't reproduce this issue, did you make sure that all your bindings are working?
Here is the code I tried to reproduce the issue with:
public partial class ListViewBugPage : ContentPage
{
public ICommand TestCmd { get; }
public ListViewBugPage()
{
TestCmd = new Command<string>((p) => Test(p));
var lv = new ListView
{
ItemsSource = new List<string> { "a", "b", "c" }
};
lv.ItemTemplate = new DataTemplate(() =>
{
var vc = new ViewCell();
var btn = new FlexButton
{
Text = "test",
HorizontalOptions = LayoutOptions.End,
CornerRadius = 6,
ForegroundColor = Color.FromHex("#fffff"),
HighlightForegroundColor = Color.FromHex("#49516F"),
BackgroundColor = Color.FromHex("#FF234389"),
HighlightBackgroundColor = Color.FromHex("#8EA4D2"),
BorderColor = Color.FromHex("#8EA4D2"),
HighlightBorderColor = Color.FromHex("#8EA4D2"),
BorderThickness = 2,
ClickedCommand = TestCmd,
ClickedCommandParameter = "tt"
};
vc.View = btn;
return vc;
});
Content = lv;
}
void Test(string p)
{
// Test
}
}
from flexbutton.
Related Issues (20)
- Image stays dark after pressed HOT 3
- Setting Icon throwing System.NullReferenceException: Object reference not set to an instance of an object. HOT 2
- NullReferenceException when using global Style HOT 3
- Support Multiple parameters for CornerRadius
- Please update to Xamarin.Forms 4
- Not working on Xamarin.Forms 4.0.0 HOT 2
- Icon Crashing on Xamarin.Forms 4.0.0 HOT 6
- not fire ClickedCommand or TouchedUpCommand HOT 2
- FlexButton won't work on iOS when using it on Xamarin Forms Project HOT 4
- A few suggestions HOT 4
- 【bug】focus status changed when clicked the flexbutton HOT 2
- IconOrientation.Top don't work in button from NuGet HOT 2
- [Android] TouchedDownCommand NullReferenceException HOT 1
- Buttons don't center in Grid HOT 1
- Feature request: Property to change icon size
- SVG Icon's doesn't work
- CornerRadius not working in Xamarin.iOS current versions (somewhat workaround inside) HOT 2
- Click event is called repeatedly when using flexbutton inside a TitleView HOT 1
- AndroidX Support HOT 1
- Rounded Corners on IOS not working HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flexbutton.