DataGrid in Avalonia UI for Linux does not show up when app is running

﹥>﹥吖頭↗ 提交于 2020-05-17 08:46:19

问题


I'm running Avalonia UI on .NET Core for Linux (Fedora). I've followed this tutorial for the DataGrid, but honestly I've added the package with the following command, instead of manually updating the .csproj.

dotnet add package Avalonia.Controls.DataGrid

After a dotnet restore and a dotnet run, I can't see any DataGrid. Anyway xaml

<StackPanel>
    <DataGrid AutoGenerateColumns="True" Items="{Binding People}"/>
</StackPanel>

and ViewModel look fine.

    public ObservableCollection<Person> People { get; }

    public MainWindowViewModel()
    {
        People = new ObservableCollection<Person>(GenerateMockPeopleTable());
    }

How can I find what is going wrong?


回答1:


I forgot to apply the DataGrid style in the App.xaml (because I'm used to WPF in Windows where the DataGrid is a standard Control):

    <StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Default.xaml"/>

The tutorial clearly states this step, so in conclusion I only changed the way to add the package in the project, just to get last version of the package reference.

  <ItemGroup>
    <PackageReference Include="Avalonia" Version="0.9.9" />
    <PackageReference Include="Avalonia.Controls.DataGrid" Version="0.9.9" />
    <PackageReference Include="Avalonia.Desktop" Version="0.9.9" />
    <PackageReference Include="Avalonia.ReactiveUI" Version="0.9.9" />
  </ItemGroup>

Aside for the version number, which obvioulsy changes with time, I can confirm that all is perfect in the above said tutorial.



来源:https://stackoverflow.com/questions/61428430/datagrid-in-avalonia-ui-for-linux-does-not-show-up-when-app-is-running

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!