MAUI CollectionView Span Property Bug - collectionview

MAUI, VS17.4 pr1, Windows.
I Set CollectionView Span value to 3, So if I have only 1 or 2 objects, the CollectionView will display nothing.
I attached a runable project on my Synology.
BugProject
BTW, ScrollBar doesn't show in the View.
Whole XAML Page:
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.VerticalListDynamicSizeItemsPage"
Title="Vertical list (dynamic item sizing)">
<StackLayout>
<Button TextColor="Wheat"
Text="Add New "
Command="{Binding AddCommand}" />
<Button TextColor="Wheat"
Text="Delete New "
Command="{Binding DeleteCommand}" />
<CollectionView HorizontalOptions="Start"
HorizontalScrollBarVisibility="Always"
ItemsLayout="VerticalGrid, 3"
ItemsSource="{Binding Monkeys}"
VerticalScrollBarVisibility="Always">
<CollectionView.ItemTemplate>
<DataTemplate>
<Grid Padding="10">
<BoxView WidthRequest="100"
HeightRequest="100"
Color="Red" />
</Grid>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>

It's a bug, I'll create a github issue.

Related

[UWP][VisualState] Custom ListViewItem hover presentation

I would like to add hover actions to a ListViewItem, but it seems that in the ListViewItem.DataTemplate the "PointerOver" state is not triggered.
I was creating a custom ItemContainerStyle but in this style, I can just set specific properties related to the TargetType 'ListViewItem'. In my case, I would like to have a button which is only visible, when the user hover over the item.
I want to use the VisualStateManager, but maybe I havn´t understood the concept behind styles, templates and user interaction with bindings in between.
Are there good references/documentation for this?
Thank you in advance
[UWP][VisualState] Custom ListViewItem hover presentation
For your requirement, the better way is
XamlBehaviors to edit the property witin DataTempate. For the detail please refer the following code.
<ListView x:Name="MyListView">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Name="GridPanel">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="InfoTextBlock" Text="{Binding}" />
<TextBlock
x:Name="FlagTextBlock"
Grid.Column="1"
Text="Hover"
Visibility="Collapsed"
>
<Interactivity:Interaction.Behaviors>
<Interactions:EventTriggerBehavior EventName="PointerEntered" SourceObject="{Binding ElementName=GridPanel}">
<Interactions:ChangePropertyAction
PropertyName="Visibility"
TargetObject="{Binding ElementName=FlagTextBlock}"
Value="Visible"
/>
<Interactions:ChangePropertyAction
PropertyName="Foreground"
TargetObject="{Binding ElementName=InfoTextBlock}"
Value="Red"
/>
</Interactions:EventTriggerBehavior>
<Interactions:EventTriggerBehavior EventName="PointerExited" SourceObject="{Binding ElementName=GridPanel}">
<Interactions:ChangePropertyAction
PropertyName="Visibility"
TargetObject="{Binding ElementName=FlagTextBlock}"
Value="Collapsed"
/>
<Interactions:ChangePropertyAction
PropertyName="Foreground"
TargetObject="{Binding ElementName=InfoTextBlock}"
Value="Black"
/>
</Interactions:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<x:String>Hello Test</x:String>
<x:String>Hello Test</x:String>
<x:String>Hello Test</x:String>
</ListView>

I want to change placeholder text in Combo Box in winRT development

I want the foregroud color of Placeholder is Foreground="#ffae19". But i get it in black color.
Can any one have solution for this :-)
<ComboBox x:Name="selectLanguage" Background="#5d198e" Foreground="#ffae19" PlaceholderText=" SELECT LANGUAGE" Width="280" Height="40" HorizontalAlignment="Center" VerticalAlignment="Center" DropDownOpened="selectLanguage_Click">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid Background="#5d198e" Width="280" Height="40">
<TextBlock Foreground="#ffae19" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding languageName}" ></TextBlock>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
You can override these default resource keys to set the color of the placeholder text without retemplating the control:
<StaticResource x:Key="ComboBoxPlaceHolderForeground" ResourceKey="SystemControlPageTextBaseHighBrush" />
<StaticResource x:Key="ComboBoxPlaceHolderForegroundFocusedPressed" ResourceKey="SystemControlHighlightAltBaseHighBrush" />
You have to edit the default styles of he combobox. Use blend for that, right click on the combobox->edit style. you will get the default style. Look out for placeholder style, and change it accordingly.

Putting an ItemContainerStyle on a Grid

Obviously ItemContainerStyle doesn't exist in a Grid, which is the problem.
My program has a ListView that displays a bunch of projects. I want to add a button to each project that gives more info, and that much I can do easily. The problem I'm encountering is the border that appears on each project, which is toggled on/off by clicking the project to show the user which are currently selected. I don't want this border to encircle my button; I want the button placed to the right of the bit with the border.
I can't put the button on a separate list or I'll get two different scroll-able lists, so it must stay within the ListView, but any border on the ListView will encircle everything in the ListView. My solution was to make a StackPanel with two Grids inside the ListView, where the first Grid has all of my old stuff and the toggle-able border and the second grid only has my button. So now I just need to move that border onto the Grid... but how?
XAML code:
<!-- Other code up above... -->
<ListView x:Name="lstAvailableProjects"
Grid.Row="1"
ItemsSource="{Binding ProjectList, Mode=TwoWay}"
Height="Auto"
Width="Auto"
SelectionMode="Multiple"
IsRightTapEnabled="True"
IsDoubleTapEnabled="False"
IsSwipeEnabled="False"
SelectionChanged="lstAvailableProjects_SelectionChanged"
Background="Transparent"
VerticalAlignment="Top"
ItemContainerStyle="{StaticResource ActiveProjectListViewStyle}"
BorderThickness="30,0,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Grid HorizontalAlignment="Stretch" Width="250" Background="{Binding Converter={StaticResource projectStateColorConverter}}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding ProjectName}"
Foreground="Black"
Margin="10 5 0 0"
FontSize="17"
VerticalAlignment="Center"
Grid.Row="0"
HorizontalAlignment="Stretch"/>
<TextBlock Text="{Binding AssignmentRole}"
Visibility="{Binding ProjectAssignmentRole, Mode=OneWay, Converter={StaticResource visibilityConverter}}"
Foreground="Black"
Margin="10 3 0 5"
FontSize="14"
Grid.Row="1"
HorizontalAlignment="Stretch"/>
<TextBlock Text="{Binding StatusText}"
Foreground="Red"
Margin="10 3 0 5"
Grid.Row="2"
FontSize="14"/>
</Grid>
<Grid>
<Button>
<Button.Template>
<ControlTemplate>
<Image Source="../Assets/setting_icon.png" Height="40" />
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Since the grid items are wrapped You cannot make changes in xaml to achieve it other than overriding the preparecontainerforitemoverride.
A little tricky hack would be to apply transform to the button.
<Button.RenderTransform>
<CompositeTransform TranslateX="100" TranslateY="100"/>
<Button.RenderTransform>

Win10 Xaml: How to get scale factor of viewbox?

I have some problem: need to make animation that starts from element inside viewbox and finishes outside viewbox
It means:
I have page where elements are placed. There is text block on the top of it and viewbox. I place gridview into this viewbox. And one moment it should start animation from gridview item
<Viewbox HorizontalAlignment="Left" Stretch="Uniform" VerticalAlignment="Top" x:Name="vbChallengeView" >
<Grid x:Name="gdChallenges">
<GridView
Margin="92,64,68,0"
x:Name="GvChallenges"
ItemsSource="{Binding Source={StaticResource GroupedItemsViewSource}}"
VerticalAlignment="Top"
HorizontalAlignment="Left"
ItemTemplate="{StaticResource ChallengeTileTemplate}"
ItemClick="GvPack_OnItemClick"
IsItemClickEnabled="True"
IsZoomedInView="False"
SelectionMode="None"
>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="Margin" Value="0,0,24,24" />
</Style>
</GridView.ItemContainerStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid MaximumRowsOrColumns="5" Orientation="Horizontal" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
</Grid>
</Viewbox>
How can I determine item size in view box and it's position relatively current window?
Thanks for any ideas

wpf calling particular array item from button

I have a Movie class with a Dim _characters = New ObservableCollection(of String)
In my MainWindow.vb i have,
Dim movies = New ObservableCollection(of Movie)
Me.parentG.DataContext = Me.movies
i want to add characters to the movie based on button click at runtime.
How can i get the particaular movie for which the character button was clicked?
MainWindow.xaml:-
<Grid Name="parentG" >
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="700"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding MovieName}" />
<Button Grid.Column="1" Content="New Character" Click="newCharacterButton_Click" Height="20" Width="100" HorizontalAlignment="Left" />
<ListBox Grid.Column="2" Name="cList" ItemsSource="{Binding Characters}">
<ListBox.ItemTemplate >
<DataTemplate >
<TextBox Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
finally figured it out. Below are the steps :-
in the button handler, convert sender to Button
get its parent, in my case it was the Grid
Get the DataContext of the Grid, convert it to (in this case), Movie
Get index of this Movie in the Movie array, assuming an index property existed for each Movie, and was set during initialization.
Add a character to this movie

Resources