Comments (25)
DataTemplateSelector
derives from DataTemplate
. So I think you can just have one property called DataTemplate FlowItemTemplate
.
Xamarin Forms ListView does it like this for the ItemTemplate
property: https://blog.xamarin.com/customizing-list-view-cells-xamarin-forms-datatemplateselector/
Optionally, if you want to offer the ability to select based on item's index, you could have a FlowItemTemplateSelector which looks like this:
public abstract class FlowItemTemplateSelector : DataTemplate
{
public abstract DataTemplate SelectTemplate(int index, object item);
}
I am not sure about having both FlowColumnCount
and FlowAutoColumnCount
. Maybe have just int? FlowColumnCount
which by default is null, meaning control auto computes the number of columns based on FlowLisView's width and flow item's width.
I would change FlowColumnDefaultMinimumWidth
to just int? FlowColumnWidth
. If it's null and you need item width, use the item's MinimumWidth
.
from dltoolkit.forms.controls.
well, you could still keep the FlowColumnTemplateSelector, something like this:
<dltoolkit:FlowListView.FlowColumnsTemplateSelectors>
<dltoolkit:FlowColumnTemplateSelector Template="{StaticResource MyTemplate1}" />
<dltoolkit:FlowColumnTemplateSelector Template="{StaticResource MyTemplate2}" />
</dltoolkit:FlowListView.FlowColumnsTemplateSelectors>
not sure this is the cleanest way..
from dltoolkit.forms.controls.
<flv:FlowListView FlowColumnCount="3" FlowItemsSource="{Binding Items}"
SeparatorVisibility="None" HasUnevenRows="false"
FlowItemTappedCommand="{Binding ItemTappedCommand}" FlowLastTappedItem="{Binding LastTappedItem}">
<flv:FlowListView.FlowColumnTemplate>
<DataTemplate>
<Label HorizontalOptions="Fill" VerticalOptions="Fill"
XAlign="Center" YAlign="Center" Text="{Binding Title}"/>
</DataTemplate>
</flv:FlowListView.FlowColumnTemplate>
</flv:FlowListView>
It also supports DataTemplateSelector
. Testers are welcome.
from dltoolkit.forms.controls.
Hi @opcodewriter,
Can I specify a DataTemplate for the cell?
Yes, FlowColumnTemplateSelector
is just a sample implementation of FlowColumnTemplateSelector
. You can create your own:
public class CustomAdvancedTemplateSelector : FlowColumnTemplateSelector
{
public override Type GetColumnType(object bindingContext)
{
// YOUR CUSTOM LOGIC HERE
if (bindingContext == null)
return typeof(ContentView);
return typeof(FlowListViewExpandCell);
}
}
If I change the width and height of a cell, does it refresh correctly?
FlowListView
is ListView
derivative, so the same behavior is expected as in ListView
. Basically it does layout of columns in one ViewCell
with usage of AbsoluteLayout
(for performance reasons).
from dltoolkit.forms.controls.
@daniel-luberda Thanks but, for the 1st question, it won't work
I need to be able to give a DataTemplate
not a Type
. Right now, you use the Type
to create an instance of the view by calling Activator.CreateInstance(columnTypes[i])
I realized this is actually not possible, I have to modify the code of the library to use DataTemplate
.
In my opinion, supporting DataTemplate
is important for people who use DataTemplate
defined in XAML, instead of creating the cell View
manually in code.
from dltoolkit.forms.controls.
I also wanted to use DataTemplate
but finally because of performance issues, I didn't. Please notice, DataTemplate
always creates a new View
instance. That's not what we want here (view reusing, etc). If you have any idea how to overcome this, please let me know.
from dltoolkit.forms.controls.
BTW: You can still define Views in XAML, the only difference is, it's a separate file.
from dltoolkit.forms.controls.
You also create a new instance now, so using a DataTemplate would be the same thing.
But yes, you would need to modify RowLayoutChanged
to check for modifications:
just need to cache the DataTemplates.
Something like this (see comments for the new code):
public class FlowListViewInternalCell : ViewCell
{
readonly IList<DataTemplate> _flowColumnDataTemplates;`
protected override void OnBindingContextChanged()
{
....
else // RECREATE COLUMNS
{
if (_rootLayout.Children.Count > 0)
{
_rootLayout.Children.Clear();
_flowColumnDataTemplates.Clear(); // clear the data templates
}
for (int i = 0; i < containerCount; i++)
{
var view = (View)columnTypes[i].CreateContent();
_flowColumnDataTemplates.Add(columnTypes[i]); // save the data templates
view.GestureRecognizers.Add(new TapGestureRecognizer()
{
Command = new Command(async (obj) =>
{
await ExecuteTapGestureRecognizer(view);
})
});
SetBindingContextForView(view, container[i]);
AddViewToLayout(view, containerCount, i);
}
}
....
}
private bool RowLayoutChanged(int containerCount, IList<DataTemplate> columnTypes)
{
// Check if desired number of columns is equal to current number of columns
if (_rootLayout.Children.Count != containerCount)
{
return true;
}
else
{
// Check if desired column view types are equal to current columns view types
for (int i = 0; i < containerCount; i++)
{
if (_flowColumnDataTemplates[i] != columnTypes[i])
{
return true;
}
//if (_rootLayout.Children[i] != columnTypes[i])
//{
// return true;
//}
}
}
return false;
}
}
from dltoolkit.forms.controls.
public abstract class FlowColumnTemplateSelector
{
public abstract DataTemplate GetColumnType(object bindingContext);
}
from dltoolkit.forms.controls.
You also create a new instance now, so using a DataTemplate would be the same thing.
Not exactly. I don't create instances every time (they're reused if possible, eg. view type didn't change). Take a look here: https://github.com/daniel-luberda/DLToolkit.Forms.Controls/blob/master/FlowListView/DLToolkit.Forms.Controls.FlowListView/FlowListViewInternalCell.cs#L253-L254
from dltoolkit.forms.controls.
Yes, I know. You can achieve same thing with DataTemplate
, you just need to save them in the FlowListViewInternalCell
so you can compare them with the new ones in the RowLayoutChanged
See my code.
I actually did this and works great.
from dltoolkit.forms.controls.
I didn't see your code yet as I'm not at home. Do you mean comparing DataTemplate
type? If it's possible, we could Obsolete
old template selectors and create new DataTemplate
based. But:
FlowListView
need a List
of DataTemplates
- I had some problems with it (it wasn't supported by XAML compiler). I don't know if anything changed in that matter.
from dltoolkit.forms.controls.
What problems did you have exactly? Maybe I can help.
from dltoolkit.forms.controls.
This works:
<DataTemplate>
<ContentView/>
</DataTemplate>
This doesn't:
<DataTemplates>
<DataTemplate>
<ContentView/>
</DataTemplate>
<DataTemplate>
<ContentView/>
</DataTemplate>
</DataTemplates>
We need multiple DataTemplate
definitions. But I didn't test it on recent XF versions.
from dltoolkit.forms.controls.
@opcodewriter I have an idea:
DataTemplate FlowColumnTemplate
property (not a list, just a single one)int FlowColumntCount
property which will be used whenFlowAutoColumnCount
is disabled- Multiple templates can be solved with
DataTemplateSelector
- That way, we still have full XAML syntax support
What do you think?
from dltoolkit.forms.controls.
@jamesl77 These are really nice suggestions. I'll implement it and obsolete old properties (they'll still work for compatibility).
from dltoolkit.forms.controls.
Compatibility is an issue, but in the same time keeping the obsolete code and mixing with new code, just for the sake of compatibility, I'm not sure is a good thing on the long run. At some point you need to get rid of it, there's a reason why it's obsolete I assume :)
Why not go to a major version of the library? The library right now is stable enough I guess? So people who use your library at current version are fine with it.
from dltoolkit.forms.controls.
Nuget 2.0.0-alpha1 released. I also created new samples project:
from dltoolkit.forms.controls.
So which way did you go in the end? Mixing old and new?
from dltoolkit.forms.controls.
For now, no compatibility. But it's very easy to add as we only need to add old properties and translate them to the new DataTemplate
based code. It won't have any impact for internal code. What do you think?
from dltoolkit.forms.controls.
I'm for clean code. Like I said before, the library is small, and pretty stable. No reason to keep deprecated code.
from dltoolkit.forms.controls.
Please, add compatibility in the new version. Old code works well.
from dltoolkit.forms.controls.
@3-50 using current released version still works and will still work. I can't speak in the name of @daniel-luberda but I think if any critical bug will appear it's still going to be fixed in current released version.
from dltoolkit.forms.controls.
@3-50 The new API allows you to use the same source data which is used in a Xamarin.Forms ListView
, just with column support. I also allows dev to use DataTemplates
which devs are used to. Old one is quite stable, I don't know of any issues with it. If some issues will be found in old version, I'll publish bug fixes release, so don't worry.
from dltoolkit.forms.controls.
@opcodewriter, @daniel-luberda Thank you for your answer.
from dltoolkit.forms.controls.
Related Issues (20)
- UWP, Disable row highlight does not work. HOT 1
- DLToolkit.Forms.Controls.FlowListView not working in UWP
- ImageCropView: "Can not access a closed stream." HOT 1
- How do you use FlowListView with design time data
- UWP issue - FlowLoadingCommand keeps loading 5 times ahead of the page size
- Footer is suddenly missing after updating Xamarin.Forms
- Does not move or zoom in XF 4 HOT 2
- Long pressing AND tap command in a list item using effects ?
- ImageCircleCrop Pan and Pinch doesnt seem to be working with latest version HOT 1
- Unable to spy items with Appium HOT 1
- Long tap event with FlowListView
- TagEntryView loses focus when a new tag is added on UWP.
- Extra new elements from OnElementChanged in UIView on iOS HOT 6
- Binding subproperty of object to FlowItemsSource throws NullRefenceException HOT 1
- Creating sections with different layouts but no grouping
- Add column in Flowlistview
- Heavy lags when connected with debugger to Android on VS2019 16.9.2 and newer HOT 2
- it won't work with ios 15 anymore, are you planning to fix it?
- Since ios 15 reload from event handler leads to immense flickering! HOT 2
- InfiniteScroll, binding FlowTotalRecords doesn't work
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 dltoolkit.forms.controls.