1

I recently upgraded to MudBazor v7 and have been working through the compilation issues. This one's foxed me and I'm not sure how to fix.

<MudTreeView Items="TreeItems" MultiSelection="true">
    <ItemTemplate>
        <MudTreeViewItem Expanded="true" Items="@context.TreeItems" Value="@context" Text="@context.Title" />
    </ItemTemplate>
</MudTreeView>

I get an error on the first line. Looking at the example the only obvious thing is that I don't have an @ before "TreeItems". Adding that doesn't change the error message.

The error I'm getting is:

CS0411 The type arguments for method 'TypeInference.CreateMudTreeView_1_CaptureParameters(IReadOnlyCollection<TreeItemData>, out IReadOnlyCollection<TreeItemData>, object, out object)' cannot be inferred from the usage. Try specifying the type arguments explicitly.

But I'm not sure how to fix this.

The property referenced by Items is:

protected HashSet<TerseTreeItemData>? TreeItems = null;

Where TerseTreeItemData is a simple class:

public class TerseTreeItemData
{
    public string Title { get; set; } = default!;
    public HashSet<TerseTreeItemData>? TreeItems { get; set; } = new();
}
2
  • You should use SelectionMode="SelectionMode.MultiSelection" instead of MultiSelection="true" Commented Jul 15, 2024 at 22:46
  • To enable multiselect, you need the code SelectionMode="SelectionMode.MultiSelection" @bind-SelectedValues="SelectedValues" and private IReadOnlyCollection<TerseTreeItemData>? SelectedValues { get; set; } after migration of MudBlazor7. github.com/MudBlazor/MudBlazor/pull/8661 Then the question would be the TreeItems type cannot be converted from HashSet to IReadOnlyCollection. Based on my research, it is not solved yet on complex T type. Commented Jul 16, 2024 at 8:14

1 Answer 1

0

Use the T="TerseTreeItemData" attribute in the MudTreeView to explicitly specify the type.

Alternatively you can use @ref as follows:

<MudTreeView @ref="@MyTree" Items="TreeItems" MultiSelection="true">
    <ItemTemplate>
        <MudTreeViewItem Expanded="true" Items="@context.TreeItems" Value="@context" Text="@context.Title" />
    </ItemTemplate>
</MudTreeView>

@code{
   public MudTreeView<TerseTreeItemData> MyTree;
   protected HashSet<TerseTreeItemData>? TreeItems = null;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.