- Home
- Forum
- Xamarin.Forms
- sfListView in Sfpopup
sfListView in Sfpopup
We have checked your requirement of “Accessing DataTemplate elements in code behind which is hosted in Xaml” and it is not possible. You must need to derive in code behind to access the DataTempalte elements, which is a limitation. Based on the code, your requirement of accessing ListView can be achieved by initializing the ListView in the code behind and you can access.
Subburaj Pandian V
My DataTemplate holds two labels in a StackLayout and gets populated from an ItemSource in the ViewModel. I understand how to build most of the content, but how to get the binding to work from code behind isn't something I understand completely. Can you help walk me through using SFListView for something like this?
<sfPopup:PopupView.ContentTemplate>
<DataTemplate>
<CollectionView
x:Name="CodesCollection"
ItemsSource="{Binding CodesReturn}"
SelectionMode="Multiple"
SelectedItems="{Binding CodesSelected, Mode=TwoWay}">
<CollectionView.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Vertical" HorizontalOptions="FillAndExpand" >
<StackLayout Orientation="Horizontal" Margin="10,5,10,1">
<Label
Margin="10,0,0,0"
Text="{Binding Code}"
FontSize="Default"
FontAttributes="Bold"
HorizontalOptions="Start"/>
<Label
Margin="0,0,10,0"
Text="{Binding Name}"
FontSize="Default"
FontAttributes="Bold"
HorizontalOptions="EndAndExpand"
HorizontalTextAlignment="End"/>
</StackLayout>
<BoxView
VerticalOptions="End"
HorizontalOptions="FillAndExpand"
Margin="15,2,15,2"
HeightRequest="2"
BackgroundColor="{StaticResource DarkGrey}"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</DataTemplate>
</sfPopup:PopupView.ContentTemplate>
|
private CollectionView _collectionView;
public MainPage()
{
........
_collectionView = new CollectionView();
_collectionView.ItemsSource = viewModel.BookInfo;
_collectionView.SelectionMode = SelectionMode.Multiple;
_collectionView.ItemTemplate = new DataTemplate(() => {
StackLayout _ParentstackLayout = new StackLayout();
///----------------------------------------------
StackLayout _stackLayout = new StackLayout();
Label _labelOne = new Label();
......
_labelOne.SetBinding(Label.TextProperty, "BookName", BindingMode.TwoWay);
Label _labelTwo = new Label();
.......
_labelTwo.SetBinding(Label.TextProperty, "BookDescription", BindingMode.TwoWay);
_stackLayout.Children.Add(_labelOne);
_stackLayout.Children.Add(_labelTwo);
//--------------------------------------------------
BoxView _boxView = new BoxView();
......
_ParentstackLayout.Children.Add(_stackLayout);
_ParentstackLayout.Children.Add(_boxView);
return _ParentstackLayout;
});
_popupContent.ContentTemplate = new DataTemplate(() => {
return _collectionView;
});
} |
Balasubramani Sundaram.
- 3 Replies
- 4 Participants
-
LE Leon
- Jul 30, 2019 06:32 AM UTC
- Aug 26, 2019 07:12 PM UTC