Comments (2)
I'm trying to change the cell type on the fly.
I try using the FlowTemplateSelector, but does not work.
How can I do?
Thanks.
Simple example:
public class TESTDLTF : ContentView
{
public TESTDLTF()
{
StackLayout sl = new StackLayout();
FlowListView hl = new FlowListView();
TemplateSelector tl = new TemplateSelector();
tl.template = 1;
hl.FlowColumnTemplate = tl;
hl.FlowColumnCount = 1;
Model model = new Model();
this.BindingContext = model;
hl.SetBinding(FlowListView.FlowItemsSourceProperty, "ListViewItems");
StackLayout stkButtons = new StackLayout() { Orientation = StackOrientation.Horizontal };
Button b1 = new Button(); b1.Text = "Load";
b1.Clicked += (sender, e) =>
{
model.Load();
};
stkButtons.Children.Add(b1);
Button b2 = new Button(); b2.Text = "Clear";
b2.Clicked += (sender, e) =>
{
model.Clear();
};
stkButtons.Children.Add(b2);
Button b3 = new Button();
b3.Text = "Change Cell 1";
b3.Clicked += (sender, e) =>
{
tl.template = 0;
hl.ForceReload();
};
stkButtons.Children.Add(b3);
Button b4 = new Button();
b4.Text = "Change Cell 2";
b4.Clicked += (sender, e) =>
{
tl.template = 1;
hl.ForceReload();
};
stkButtons.Children.Add(b4);
sl.Children.Add(stkButtons);
sl.Children.Add(hl);
this.Content = sl;
}
public class TemplateSelector : FlowTemplateSelector
{
public int template { get; set; }
readonly DataTemplate _cell1 = new DataTemplate(typeof(Cell));
readonly DataTemplate _cell2 = new DataTemplate(typeof(Cell2));
protected override DataTemplate OnSelectTemplate(object item, int columnIndex, BindableObject container)
{
if (template == 0) return _cell1;
if (template == 1) return _cell2;
return null;
}
}
public class Cell : ContentView
{
public Cell()
{
Label lb1 = new Label();
lb1.SetBinding(Label.TextProperty, "Code");
StackLayout sl = new StackLayout();
sl.Children.Add(lb1);
this.Content = sl;
}
}
public class Cell2 : ContentView
{
public Cell2()
{
Label lb1 = new Label();
lb1.SetBinding(Label.TextProperty, "Code");
Label lb2 = new Label();
lb2.SetBinding(Label.TextProperty, "Name");
StackLayout sl = new StackLayout();
sl.Children.Add(lb1);
sl.Children.Add(lb2);
this.Content = sl;
}
}
public class Model: INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChangedEventHandler handler = PropertyChanged;
if (handler != null)
{
handler(this, new PropertyChangedEventArgs(propertyName));
}
}
public List<Entity> _ListViewItems { get; set; }
public List<Entity> ListViewItems
{
get
{
return _ListViewItems;
}
set
{
_ListViewItems = value;
OnPropertyChanged("ListViewItems");
}
}
public void Load()
{
List<Entity> l = new List<Entity>();
l.Add(new Entity() { Code = "1", Name = "zxczxczxc" });
l.Add(new Entity() { Code = "2", Name = "zxczxczxc" });
l.Add(new Entity() { Code = "3", Name = "zxczxczxc" });
l.Add(new Entity() { Code = "4", Name = "zxczxczxc" });
l.Add(new Entity() { Code = "5", Name = "zxczxczxc" });
l.Add(new Entity() { Code = "6", Name = "zxczxczxc" });
l.Add(new Entity() { Code = "7", Name = "zxczxczxc" });
this.ListViewItems = l;
}
public void Clear()
{
List<Entity> l = new List<Entity>();
this.ListViewItems = l;
}
}
public class Entity
{
public string Code { get; set; }
public string Name { get; set; }
}
}
from dltoolkit.forms.controls.
You should base only on OnSelectTemplate
method parameters, item
is a BindingContext
public class TemplateSelector : FlowTemplateSelector
{
readonly DataTemplate _cell1 = new DataTemplate(typeof(Cell));
readonly DataTemplate _cell2 = new DataTemplate(typeof(Cell2));
protected override DataTemplate OnSelectTemplate(object item, int columnIndex, BindableObject container)
{
if (columnIndex == 0) return _cell1;
if (columnIndex == 1) return _cell2;
return null;
}
}
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.