Multi-level bullet list in .NET MAUI - maui

I need to create a multi-level bullet list in my .NET MAUI app which is at least 2 levels, possibly 3, even 4 levels deep.
How do I handle this in XAML or do I need to handle it in Blazor?

If I understand correctly, you could use a Grid. ColumnDefinitions property could be used to set different level while RowDefinitions could be used to set items. You could use either Absolute or Star value to set the width or height.
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5*" />
</Grid.ColumnDefinitions>
For more info, you could refer to .NET MAUI Grid.

Related

Pass the VisualState of CollectionView Item VisualElement to its child VisualElements

I am having the following situation:
CollectionView, each item is Border, that contains other controls.
When selected, the VisualState of the Border changes to selected. The child controls however do not have a change in their state.
Is there an easy way to link/pass those VisualStates to all child controls?
(cascade, 2,3,4 and more levels deeper)
Edit: I know how to use Triggers, Setters in Styles and other approaches to change the UI of the application. The question is specifically for changing the VisualState of the nested VisualElements. Cannot find anything anywhere on this matter.
You can try to set state on multiple elements.
Visual states could be attached to and operated on single elements. And it's also possible to create visual states that are attached to a single element, but that set properties on other elements within the same scope. This avoids having to repeat visual states on each element the states operate on.
The following example shows how to set state on multiple objects, from a single visual state group:
<StackLayout>
<Label Text="What is the capital of France?" />
<Entry x:Name="entry"
Placeholder="Enter answer" />
<Button Text="Reveal answer">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal" />
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Property="Scale"
Value="0.8" />
<Setter TargetName="entry"
Property="Entry.Text"
Value="Paris" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Button>
</StackLayout>
Note: Property paths are unsupported in Setter elements that specify the TargetName property.
You can also try to define custom visual states, for more information, you can check: Define custom visual states .

Change ImageButton source based on Theme in xaml

I want to change the Source of an ImageButton in xaml based on the Theme (i.e. Light vs Dark). I get a System.NullReferenceException 'Object reference not set to an instance of an object.' when I use the following:
<ImageButton
Grid.Row="1"
Margin="10"
Command="{Binding CreateCommand}"
Source="{AppThemeBinding Light=add_box_black_48dp.svg, Dark=add_box_light_48dp.svg}"
HorizontalOptions="End"
VerticalOptions="End"/>
If I change the Source to the following everything works
Source="add_box_white_48dp"
Can I use AppThemeBinding to change the ImageButton Source in this way?
<Edited on 6/4/2022 to show xaml for cases that work and those that do not work. Also changed the names of the svg files to reflect light and dark cases>
I am using Visual Studio Community 2022 (64-bit) - Preview
Version 17.3.0 Preview 1.1
This ImageButton xaml throws the exception:
<ImageButton
Margin="10"
Command="{Binding CreateNewAccountCommand}"
Source="{AppThemeBinding Light=add_light.svg, Dark=add_dark.svg}"
HorizontalOptions="End"
VerticalOptions="End"
BackgroundColor="#376489"
CornerRadius="8"
WidthRequest="36"
HeightRequest="36">
</ImageButton>
This ImageButton xaml works and does not throw an exception
<ImageButton
Margin="10"
Command="{Binding CreateNewAccountCommand}"
Source="add_light.svg"
HorizontalOptions="End"
VerticalOptions="End"
BackgroundColor="#abdbe3"
CornerRadius="8"
WidthRequest="36"
HeightRequest="36">
</ImageButton>
This also works and does not throw an exception
<ImageButton
Margin="10"
Command="{Binding CreateNewAccountCommand}"
Source="add_dark.svg"
HorizontalOptions="End"
VerticalOptions="End"
BackgroundColor="#376489"
CornerRadius="8"
WidthRequest="36"
HeightRequest="36">
</ImageButton>
To work cross-platform, refer to .png files. These get built automatically by Maui:
Each image resource needs Property/BuildAction: "MauiImage".
Refer to .png in xaml:
Source="{AppThemeBinding Light=add_box_black_48dp.png, Dark=add_box_light_48dp.png}"
Verified by modifying Maui project's default MainPage, to say:
<Image Source="{AppThemeBinding Light=dotnet_bot.png, Dark=dotnet_bot.png}" ... />
This refers to a Media item dotnet_bot.svg, which (I infer) gets converted by "MauiImage" into a .png resource.
NOTE: Maybe the plan is to be able to leave off the extension. This works on Android, but the image does not show on Windows:
<!-- Doesn't work currently on Windows -->
<Image Source="{AppThemeBinding Light=dotnet_bot, Dark=dotnet_bot}" ... />

How to reference element of navigation property in detail view?

I am trying to get Data from a navigation property to display in my detailview.
Image shows the definition of the entities in sap gateway
The association is a 1:1 association.
If I use the link to the navigation property directly it gives the proper result:
link:
/sap/opu/odata/namespace/PROJECTBUILDER_SRV/PROJEKTSet('00002403')/TechnicalSpecs
result:
<entry xmlns="http://www.w3.org/2005/Atom" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xml:base="/sap/opu/odata/namespace/PROJECTBUILDER_SRV/">
<id>/sap/opu/odata/namespace/PROJECTBUILDER_SRV/TECHNICAL_SPECSSet('Test%20Service%202')</id>
<title type="text">TECHNICAL_SPECSSet('Test%20Service%202')</title>
<updated>2021-12-02T13:06:38Z</updated>
<category term="PROJECTBUILDER_SRV.TECHNICAL_SPECS" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"/>
<link href="TECHNICAL_SPECSSet('Test%20Service%202')" rel="self" title="TECHNICAL_SPECS"/>
<content type="application/xml">
<m:properties>
<d:Equipment>Test Service 2</d:Equipment>
<d:Pspnr>00002403</d:Pspnr>
<d:Turbine>TurbineName</d:Turbine>
<d:NominalPowerE>2,5 MW</d:NominalPowerE>
<d:NominalPowerM>4 MW</d:NominalPowerM>
<d:RotorDiameter>80 M</d:RotorDiameter>
<d:RotorSpeed>5,92/12 RPM</d:RotorSpeed>
<d:GridFrequency>50 HZ</d:GridFrequency>
<d:GeneratorSpeed>379 RPM</d:GeneratorSpeed>
<d:GearboxRatio>50,6</d:GearboxRatio>
<d:NominalTorque>4700 KNM</d:NominalTorque>
<d:MaxTorque>9800 KNM</d:MaxTorque>
</m:properties>
</content>
</entry>
But in ui5 view the fields stay empty (the getEntity-Method isn't called either) - so I must be referencing it in a wrong way:
The view I am in uses a route to PROJEKTSet and inside this view I am trying to say:
<m:Input value="{/TechnicalSpecs>/Equipment}" editable="false" visible="true" id="DetailEquipment"/>
What is the correct way to get the value "Equipment" of Entity TechnicalSpecs, which has an association with PROJEKT?

Unable to create XAML array of views with mvvm:ViewModelLocator

I want to make a xamarin forms carousel view containing 2 custom views. I have this code:
<ContentPage x:Class="MainView" xmlns:mvvm="clr-namespace:Prism.Mvvm;assembly=Prism.Forms" xmlns:views="clr-namespace:Views" x:Name="Main">
<CarouselView>
<CarouselView.ItemsSource>
<x:Array Type="{x:Type View}">
<views:View1 mvvm:ViewModelLocator.AutowirePartialView="{x:Reference Main}" />
<views:View2 mvvm:ViewModelLocator.AutowirePartialView="{x:Reference Main}" />
</x:Array>
</CarouselView.ItemsSource>
<CarouselView.ItemTemplate>
<DataTemplate>
<ContentView Content="{Binding .}" />
</DataTemplate>
</CarouselView.ItemTemplate>
</CarouselView>
</ContentPage>
When launching the app, exception is thrown:
Xamarin.Forms.Xaml.XamlParseException: 'Position 80:37. Can not find
the object referenced by Main'
If I just set both views as direct content of the main page, it works fine. What am I doing wrong?
Is there a way to make the collection of views through the MainViewModel?

Problem Binding Commands to TreeViewItem using MVVMLight

I'm trying to use MVVMLight to bind a TreeViewItem Selected event to a command.
The TreeViewItem's are defined in a HierarchicalDataTemplate so I cannot add Interaction.Triggers (as shown below)
<HierarchicalDataTemplate
x:Key="TreeViewItemTemplate"
ItemsSource="{Binding ChildReportViewModels}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Selected">
<MvvmLight_Command:EventToCommand Command="{Binding LoadReportCommand, Mode=OneWay}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</HierarchicalDataTemplate>
How else can I add the EventTrigger to each TreeViewItem?
Thanks.
I forgot about this question.
For future ref, here's the solution I used...
Instead of trying to bind the EventToCommand to the Selected event of the TreeView,
I bound it to the MouseLeftButtonUpEvent of the TextBlock declared in the HierarchicalDataTemplate for TreeViewItems.
<HierarchicalDataTemplate
x:Key="TreeViewItemTemplate"
ItemsSource="{Binding ChildReportViewModels}"
ItemContainerStyle="{StaticResource TreeViewItemContainerStyle}">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseLeftButtonUp">
<gs_cmd:EventToCommand Command="{Binding LoadPublicationCommand, Mode=OneWay}" CommandParameter="{Binding}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</StackPanel>
</HierarchicalDataTemplate>
I have not much knowledge about MVVMLight and especially about EventTrigger.
But since there is no answer to your qestion yet the codeplex article TreeViewWithViewModel might help. It shows how to bind to SelectedItem and IsExpanded Properties in a wpf-treeview and how these can be used to implement load on demand in the treeview.