AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology

Home Page:https://avaloniaui.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot add datagrid control

tchtang opened this issue · comments

Describe the bug

I create new project, run in desktop can open window with message 'Welcome to Avalonia'
Want to add datagrid, but cannot do so

image

To Reproduce

  1. from https://docs.avaloniaui.net/docs/reference/controls/datagrid/

  2. dotnet add package Avalonia.Controls.DataGrid

  3. get compile error
    image
    image

  4. Update patch
    image

become

image

  1. Press F5, cannot run
    image

  2. Have not add datagrid control yet
    image

Expected behavior

No response

Avalonia version

11.1.0-beta2

OS

Windows

Additional context

No response

You need to upgrade to 11.0.10 instead of 11.1beta

version was 11.0.2
after done step 2, has compile error

cannot find version 11.0.1
installed from https://marketplace.visualstudio.com/items?itemName=AvaloniaTeam.AvaloniaVS

nuget also no 11.0.1
image

11.0.10

link please?

  1. can see welcome message from 11.0.2
    image

  2. from https://www.nuget.org/packages/Avalonia/11.0.10
    dotnet add package Avalonia --version 11.0.10
    image

  3. compile no error, but F5
    image
    whole window only can see title bar

installed version 11.5 become 11.0.2

image

nuget version has nothing to do with extension. just open your csproj file and edit every version related to Avalonia to 11.0.10.

And using nuget manager you can choose the version here
image

thank you your help but still cannot upgrade to 11.0.10
kindly provide link to upgrade all version to 11.0.10

image

image

image

commented

Please don't open bug reports for questions. Use discussions instead. Will convert this one later when I have time to.

When I say every, I mean every. Your desktop, android, ios and browser project is still 11.0.2

Also the VS package manager is a real pain to use with a large dependency chain like Avalonia (it often complains about transient conflicts which forces you to upgrade things in a specific order). It's easier to just manually upgrade everything by editing your project file. You should be able to upgrade all packages fairly easily though by checking the box on the updates tab.

@rabbitism do you see below error?

@thevortexcloud may i know how to edit project file

If you are using a project using the new SDK format (which you likely are if you have made a new project), you can double click the project in the solution explorer. If you are using the old format, you need to unload the project and then right click it, and press edit. Or you can just open it directly with an external text editor.

  • kindly please give me the step, isnt sample as below,

image

  • in .csproj file add all packagereference for below

image

  • that is

image

  • and so on

You may also need to trigger a restore. Try running dotnet restore in a terminal while inside your project directory. While you are there, also run dotnet new update to update your Avalonia templates. If it still does not work after all that, then you should be able to create a new solution using the latest templates.

cannot edit .csproj file
image

original .csproj is
image

You may also need to trigger a restore. Try running dotnet restore in a terminal while inside your project directory. While you are there, also run dotnet new update to update your Avalonia templates. If it still does not work after all that, then you should be able to create a new solution using the latest templates.

isnt using
image
developer console?

In case of android project, you will also need to change the TargetFramework to net7.0-android.

may i know how to change TargetFramework to net7.0-android.

target framework: 7.0, rebuild solution, error
image

target framework: 6.0, rebuild solution, error
image

I suggest reading the official .NET docs and watching/reading a few tutorials. Most of this has nothing directly to do with Avalonia.

https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview
https://learn.microsoft.com/en-us/dotnet/standard/frameworks

Anyway, you should not have android/iOS package references in a project that does not target the correct TFM.

You have mixed Desktop, iOS and Android package. Single project is experimetal feature.

You should use following comnand to create new Cross platform project from template

dotnet new avalonia.xplat  -n MyApp

or select Cross Platform Application template.

After creation. You have more project, each for plat (MyApp.Android.cspoj, ...).

The Cross plat xaml and code should put into MyApp.csproj

Add DataGrid package to MyApp.csproj

Rebuild the solution

Edit app.axaml and add DataGrid Style