Skip to content

Commit 2cc8e99

Browse files
Pedro JesusPedro Jesus
authored andcommitted
attachedProperty for the win!?
1 parent 4e8d2da commit 2cc8e99

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

samples/PJ.ContextActions.Sample/AttachedP.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static class AttachedP
5858

5959
public static void SetContextActions(CollectionView cv, IEnumerable<MenuItem> items) => cv.SetValue(ContextActionsProperty, items);
6060

61-
public static IEnumerable<MenuItem> GetContextActions(CollectionView cv) => (IEnumerable<MenuItem>)cv.GetValue(ContextActionsProperty);
61+
public static List<MenuItem> GetContextActions(CollectionView cv) => (List<MenuItem>)cv.GetValue(ContextActionsProperty);
6262
}
6363

6464

samples/PJ.ContextActions.Sample/MainPage.xaml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
66
xmlns:local="clr-namespace:PJ.ContextActions.Sample">
77

8-
<local:MyCV x:Name="cv">
8+
9+
<CollectionView x:Name="cv">
10+
<local:AttachedP.ContextActions>
11+
<local:MenuItem Clicked="MenuItem_Clicked" Text="Primeiro" />
12+
<local:MenuItem Command="{Binding ClickCommand}" Text="Segundo" />
13+
</local:AttachedP.ContextActions>
14+
15+
<CollectionView.ItemTemplate>
16+
<DataTemplate>
17+
<Label Text="{Binding .}"/>
18+
</DataTemplate>
19+
</CollectionView.ItemTemplate>
20+
</CollectionView>
21+
22+
<!-- <local:MyCV x:Name="cv">
923
1024
<local:MyCV.Header>
1125
<Label
@@ -28,6 +42,6 @@
2842
<Label FontSize="30" Text="{Binding .}" />
2943
</DataTemplate>
3044
</local:MyCV.ItemTemplate>
31-
</local:MyCV>
45+
</local:MyCV> -->
3246

3347
</ContentPage>

samples/PJ.ContextActions.Sample/MauiProgram.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ public static MauiApp CreateMauiApp()
2626
{
2727
#if IOS || ANDROID || WINDOWS
2828
h.AddHandler(typeof(MyCV), typeof(MyCVHandler));
29+
30+
h.AddHandler(typeof(CollectionView), typeof(MyCVHandler));
2931
#endif
3032
});
3133

samples/PJ.ContextActions.Sample/Platforms/Android/MyCollectionViewHandler.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ public override void OnBindViewHolder(RecyclerView.ViewHolder holder, int positi
4949
{
5050
base.OnBindViewHolder(holder, position);
5151

52-
if (collectionView is not MyCV myCV)
52+
// var items = AttachedP.GetContextActions(collectionView as CollectionView);
53+
54+
if (collectionView is not CollectionView myCV)
5355
{
5456
return;
5557
}
5658

57-
var contextActions = myCV.ContextActions;
59+
// var contextActions = myCV.ContextActions;
60+
var contextActions = AttachedP.GetContextActions(myCV);
5861
if (MenuItems is null && contextActions.Count > 0)
5962
{
6063
MenuItems = new MenuItem[contextActions.Count];

0 commit comments

Comments
 (0)