C
C#randomrider

✅ Avalonia not showing rows in datagrid

There are no rows in my datagrid in Avalonia, the headers are visible. I've checked if my list is empty, but it isn't. There are also no errors, even when I change the bindings to bindings that don't exist. I did include the Datagrid package and reference in App.AXAML. It is the same issue as in https://discord.com/channels/143867839282020352/1113257710595616819. Help would be appreciated.
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
J
Jimmacle45d ago
do you have the source code and screenshots of the issue?
R
randomrider45d ago
ObservableCollection<BEURTINFO> BeurtenGRID {get;} = new ObservableCollection<BEURTINFO>();//in top of code
//in function
for (int i = 0; i < jsonObj.Length; i++)//jsonObj is the parsed JSON string from server
{
BeurtenGRID.Add(new BEURTINFO( jsonObj[i].username, formatTime(Convert.ToInt32(jsonObj[i].time)).ToString(), jsonObj[i].devices.ToString()));
}
//bottom of code
public class BEURTINFO
{
public string Username { get; set; }
public string Time { get; set; }
public string Devices { get; set; }
public BEURTINFO(string username, string time, string devices) {
Username = username;
Time = time;
Devices = devices;
}
}
ObservableCollection<BEURTINFO> BeurtenGRID {get;} = new ObservableCollection<BEURTINFO>();//in top of code
//in function
for (int i = 0; i < jsonObj.Length; i++)//jsonObj is the parsed JSON string from server
{
BeurtenGRID.Add(new BEURTINFO( jsonObj[i].username, formatTime(Convert.ToInt32(jsonObj[i].time)).ToString(), jsonObj[i].devices.ToString()));
}
//bottom of code
public class BEURTINFO
{
public string Username { get; set; }
public string Time { get; set; }
public string Devices { get; set; }
public BEURTINFO(string username, string time, string devices) {
Username = username;
Time = time;
Devices = devices;
}
}
No description
R
randomrider45d ago
<Design.DataContext>
<vm:MainViewModel></vm:MainViewModel>
</Design.DataContext>
<DataGrid Loaded="DataGrid_Loaded"
ItemsSource="{Binding BeurtenGRID}"
x:Name="beurtenGrid"
Margin="20"
IsReadOnly="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserSortColumns="True"
GridLinesVisibility="All"
BorderThickness="1" BorderBrush="Gray">
<DataGrid.Columns>
<DataGridTextColumn Header="Gebruikersnaam" Binding="{Binding Username}" Width="300" />
<DataGridTextColumn Header="Duratief/Data" Binding="{Binding Time}" Width="200"/>
<DataGridTextColumn Header="Aantal apparaten" Binding="{Binding Devices}" Width="200">
</DataGrid.Columns>
</DataGrid>
<Design.DataContext>
<vm:MainViewModel></vm:MainViewModel>
</Design.DataContext>
<DataGrid Loaded="DataGrid_Loaded"
ItemsSource="{Binding BeurtenGRID}"
x:Name="beurtenGrid"
Margin="20"
IsReadOnly="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserSortColumns="True"
GridLinesVisibility="All"
BorderThickness="1" BorderBrush="Gray">
<DataGrid.Columns>
<DataGridTextColumn Header="Gebruikersnaam" Binding="{Binding Username}" Width="300" />
<DataGridTextColumn Header="Duratief/Data" Binding="{Binding Time}" Width="200"/>
<DataGridTextColumn Header="Aantal apparaten" Binding="{Binding Devices}" Width="200">
</DataGrid.Columns>
</DataGrid>
J
Jimmacle45d ago
what is the height of the data grid (using the debug tools)? are you sure it actually has room to display the table? or try specifying a fixed height to see if that makes a difference
R
randomrider45d ago
I changed the height and still nothing
No description
L
leowest45d ago
did u add the styles in the resources?
R
randomrider45d ago
yes i did in app.axaml
L
leowest45d ago
App.axaml needs to have
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
ok
R
randomrider45d ago
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="GIP_av.App"
RequestedThemeVariant="Light">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
</Application.Styles>
</Application>
<Application xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="GIP_av.App"
RequestedThemeVariant="Light">
<!-- "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options. -->

<Application.Styles>
<FluentTheme />
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml"/>
</Application.Styles>
</Application>
L
leowest45d ago
mmm could it be a color issue? can u set the background to say black or the columns text color to black I've had that issue on my example
R
randomrider45d ago
in the documentation it says that it uses MVVM for biding, could it be that?
L
leowest45d ago
I mean it depends on your code I would need to see more of your project to tell if you're using MVVM or not but the fact your using ObservableCollection assuming that is a ViewModel or in the DataContext it should load can you show me an image of your solution explorer so I can see what u have in there preferable with the folders collapsed
L
leowest45d ago
if u have something like this
No description
L
leowest45d ago
changes are u already have the MVVM hooked and just didnt know
R
randomrider45d ago
No description
L
leowest45d ago
ok so you only have MVVM set for 1 view
L
leowest45d ago
can u show me the code for these 2 files
No description
L
leowest45d ago
and
L
leowest45d ago
No description
L
leowest45d ago
please use the site below to $paste it
M
MODiX45d ago
If your code is too long, you can post to https://paste.mod.gg/ and copy the link into chat for others to see your shared code!
R
randomrider45d ago
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="GIP_av.BeurtenBekijken"
xmlns:vm="using:GIP_av.ViewModels"
Title="BeurtenBekijken"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="NoChrome"
ExtendClientAreaTitleBarHeightHint="-1"
WindowState="Maximized"
SystemDecorations="BorderOnly">
<StackPanel>
<Design.DataContext>
<vm:MainViewModel></vm:MainViewModel>
</Design.DataContext>
<DataGrid Loaded="DataGrid_Loaded"
ItemsSource="{Binding BeurtenGRID}"
x:Name="beurtenGrid"
Margin="20"
IsReadOnly="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserSortColumns="True"
GridLinesVisibility="All"
BorderThickness="1" BorderBrush="Gray"
Height="300">
<DataGrid.Columns>
<DataGridTextColumn Header="Gebruikersnaam" Binding="{Binding Username}"
Width="300" Foreground="Black" />
<DataGridTextColumn Header="Duratief/Data" Binding="{Binding Time}"
Width="200"/>
<DataGridTextColumn Header="Aantal apparaten" Binding="{Binding Devices}"
Width="200"/>
</DataGrid.Columns>
</DataGrid>
<Button
Click="Sluiten_Click"
FontSize="18"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
>Sluiten</Button>
</StackPanel>
</Window>
<Window xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="GIP_av.BeurtenBekijken"
xmlns:vm="using:GIP_av.ViewModels"
Title="BeurtenBekijken"
ExtendClientAreaToDecorationsHint="True"
ExtendClientAreaChromeHints="NoChrome"
ExtendClientAreaTitleBarHeightHint="-1"
WindowState="Maximized"
SystemDecorations="BorderOnly">
<StackPanel>
<Design.DataContext>
<vm:MainViewModel></vm:MainViewModel>
</Design.DataContext>
<DataGrid Loaded="DataGrid_Loaded"
ItemsSource="{Binding BeurtenGRID}"
x:Name="beurtenGrid"
Margin="20"
IsReadOnly="False"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserSortColumns="True"
GridLinesVisibility="All"
BorderThickness="1" BorderBrush="Gray"
Height="300">
<DataGrid.Columns>
<DataGridTextColumn Header="Gebruikersnaam" Binding="{Binding Username}"
Width="300" Foreground="Black" />
<DataGridTextColumn Header="Duratief/Data" Binding="{Binding Time}"
Width="200"/>
<DataGridTextColumn Header="Aantal apparaten" Binding="{Binding Devices}"
Width="200"/>
</DataGrid.Columns>
</DataGrid>
<Button
Click="Sluiten_Click"
FontSize="18"
HorizontalAlignment="Center"
VerticalAlignment="Bottom"
>Sluiten</Button>
</StackPanel>
</Window>
L
leowest45d ago
post it to the link pls easier to read since its multiple files
R
randomrider45d ago
ok
L
leowest45d ago
or if u have github u can push and i can check your github too either way works
R
randomrider45d ago
i pasted it in the link
L
leowest45d ago
u click save then u copy and paste the url
R
randomrider45d ago
BlazeBin - rndklfgizixx
A tool for sharing your source code with the world!
L
leowest45d ago
where is the rest? its 6 files
R
randomrider45d ago
oh sorry only read the first messege
L
leowest45d ago
but yeah you're not using MVVM you're using code behind at least for the file u sent in
R
randomrider45d ago
how do i use mvvm then?
L
leowest45d ago
I will check the other files and then I will try to explain I am trying to figure out how are u managing the views for now
R
randomrider45d ago
BlazeBin - zuoxcpvvjbwm
A tool for sharing your source code with the world!
L
leowest45d ago
did u change in the
R
randomrider45d ago
i just use the name property like 'x:Name'
L
leowest45d ago
ok so did u change in the App.axaml.cs the window it was loading? because otherwise when u run you app it would open MainWindow and not BeurtenBekijken
R
randomrider45d ago
no because the mainwindow is meant to be opened first and from that window you can open other windows
R
randomrider45d ago
https://github.com/JerkoLannoo/GIP_avalonia here is the entire source code
GitHub
GitHub - JerkoLannoo/GIP_avalonia: GIP terminal Avalonia
GIP terminal Avalonia. Contribute to JerkoLannoo/GIP_avalonia development by creating an account on GitHub.
L
leowest45d ago
am I blind I dont see where u open it ok thx let me check AH ok found it
R
randomrider45d ago
it opens from 'dashboard.axaml'
L
leowest45d ago
ok yeah so you're writing this as if it was winform that is not normally how u work with xaml
R
randomrider45d ago
yes
L
leowest45d ago
this is normally how it goes down MainWindow -- this is just a shell |-- MainView -- this is the main page that open inside the shell MainWindow So you would have a navigation on either your MainWindow or MainView where u would open the new pages u dont normally open completely new windows like u do in winforms with WPF/Avalonia that's why I was a bit confused but that aside as for MVVM, you have your View, then you Have the ViewModel, and then you bind the 2 together via the DataContext so usually u dont write code in the axaml.cs just in some scenarios so in your case in the file BeurtenBekijken you could do
public BeurtenBekijken()
{
DataContext = this;
InitializeComponent();
}
public BeurtenBekijken()
{
DataContext = this;
InitializeComponent();
}
and your binding should work its not the best approach but given how u've gone so far its way too much for me help u fix to go back to right MVVM and how to write xaml
R
randomrider45d ago
thanks! this worked for me! i write my code this way because i am used to winforms and i just need something that runs fast on a raspberry pi
L
leowest45d ago
I strongly suggest u tried writing another simpler project following MVVM u will see how much easier it is and how it improves your code 10 fold yeah I understood that, but its a shame at the same time because you're losing a lot doing so in that manner $close
M
MODiX45d ago
Use the /close command to mark a forum thread as answered
R
randomrider45d ago
so you can just access the axaml elements directly from c# then?
L
leowest45d ago
yes but then u break MVVM completly by naming the controls i.e.: like U said earlier... x:Name="Something" MVVM is really not that hard, but if you're coming from winform its not simple to digest
R
randomrider45d ago
ok, but i'll first try to finish to program this way, and than try to use mvvm, since most of the UI is static
L
leowest45d ago
that's fair reason why I showed how to apply the DataContext with what u had 😉
R
randomrider45d ago
ok, thank again for the help! Maybe I should use the MVVM method, because now it can't compile because it can't find tje bindings.
L
leowest45d ago
what is the error message
R
randomrider45d ago
Avalonia error AVLN:0004: Unab le to resolve suitable regular or attached property ItemsSource on type Avalonia.Controls.DataGrid:Avalonia.Controls.Da taGrid Line 15, position 4.
L
leowest45d ago
did u update your github iwth the latest changes? that is on the datagrid file right?
R
randomrider45d ago
yes
L
leowest45d ago
are u sure it s up to date?
R
randomrider45d ago
i've just updated it in github
L
leowest45d ago
ok try cleaning and rebuilding your solution
R
randomrider45d ago
i get the same error it does build fine though
L
leowest45d ago
it builds without error and fails when u run?
R
randomrider45d ago
no, it builds and runs fine but when i compile for arm64 linuc in cmd it throws that error
L
leowest45d ago
TIP: next time when its working, commit, then keep working. Do small git commits so u can evaluate changes that could have broken things dont write 2k lines of code to commit commit in small chunks did A, its working, commit ah ok that is a different problem you have libraries that are specific to windows u have to change that
R
randomrider45d ago
but when i don't include the binding it compiles just fine it is this line: "ItemsSource="{Binding BeurtenGRID}""
L
leowest45d ago
bad if that was the case it would not work on windows either
L
leowest45d ago
Zen.Barcode.Rendering.Framework 3.1.10729.1
Barcode Rendering Framework Release.3.1.10729 from http://barcoderender.codeplex.com/ 30th June 2014 The bar-code rendering framework quite simply encapsulates the native rendering of barcode symbologies without requiring third-party fonts. The framework makes it easy to define new symbologies and use the resultant images from web or forms appl...
L
leowest45d ago
you have a few libraries that do not run on linux so start by removing those and elimitate the possibilities
R
randomrider45d ago
ok
L
leowest45d ago
also remove this to avoid confusion as well x:Name="beurtenGrid" since you're not using it
R
randomrider45d ago
ok
L
leowest45d ago
check your Error List for any other warnings about libraries that work on windows only I think it will be NU.... error
L
leowest45d ago
No description
L
leowest45d ago
it will show like that so basically anything that specifically targets .net framework relies on api's exclusive to windows and will not run on linux or mac etc
R
randomrider45d ago
github is updated
L
leowest45d ago
ok did u remvoe all the libraries that had the issue mentioned in the image above? think there was 3 or 4
R
randomrider45d ago
yes, no nuget errors anymore
L
leowest45d ago
ok and u still get that binding error on linux?
R
randomrider45d ago
yes
L
leowest45d ago
are u publishing? what options did u select
R
randomrider45d ago
this is the command:
dotnet build "./GIP_av.Desktop.csproj" -c Release -r linux-arm64 -v q /clp:ErrorsOnly
dotnet build "./GIP_av.Desktop.csproj" -c Release -r linux-arm64 -v q /clp:ErrorsOnly
L
leowest45d ago
then u zipped the linux-arm64 folder and unzipped the whole thing on your linux?
R
randomrider45d ago
no, i build for linux on my windows pc and move it to linux and than run it on linux
L
leowest45d ago
yes but you move the whole fodler with all the files inside of it not tjust theg exe or dll right
L
leowest45d ago
No description
L
leowest45d ago
No description
L
leowest45d ago
u need all the files inside
R
randomrider45d ago
yes i do that, but i get an error when compiling it for linux on my windows pc
L
leowest45d ago
mmm
R
randomrider45d ago
so the linux-arm folder doesnt update
L
leowest45d ago
ok let me check ah I think I see the issue moment ok open your Desktop csproj and remove this line
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.2" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="11.0.2" />
it will only leave 1 line inside the itemsgroup then rigth click your GIP_av project and open nuget and install the datagrid there then clean/rebuild then u should be able to build to arm64
L
leowest45d ago
No description
R
randomrider45d ago
yes it worked
L
leowest45d ago
👍 so basically it was nothing to do with the binding but the library being on the wrong project causing it to not recognize the control properties
R
randomrider45d ago
but how did it manage to run on windows then?
L
leowest45d ago
¯\_(ツ)_/¯ magic maybe because you were running on debug mode and for whatever reason in debug it just works on windows either way u dont want to add anything to Desktop project UNLESS is code specifically to run from it anything else should be on the library project as its what gets run on everything out of curiosity does it run on your raspberry?
R
randomrider45d ago
yes, and pretty fast
L
leowest45d ago
nice to know I have one myself but never ran avalonia on it so its all working now?
R
randomrider45d ago
yes, but there is one visual bug. It shows one row, and then when you scroll it shows the rest and makes the table bigger
R
randomrider45d ago
No description
No description
L
leowest45d ago
make sure u commit the last changes u did since building its working now 😉 well u dont define a height maybe if u do it might render differently Ah I see because its StackPanel change that to a Grid and see if it changes
R
randomrider45d ago
yes but then the margin top is too big, so i'll just use stackpanel width datagrid on fixed height
L
leowest45d ago
well u will have rendering issues then its not a visual bug but how stackpanel works to render things with grid all u have to do is split into 2 rows give the first * and the second however much space u want to give your button add Grid.Row="1" to your button and that's it
R
randomrider45d ago
yes that worked
L
leowest45d ago
👍
R
randomrider45d ago
thanks for your help (again)!
L
leowest45d ago
no worries just a reminder you should really start a fresh project later and learn MVVM with AValonia and Community Toolkit u will much easier all of waht u did turns into and how much cleaner the codes turns as well
R
randomrider45d ago
ok, i will definitely look into that
Want results from more Discord servers?
Add your server
More Posts
Infinite loop```c# /// ------------------------------------------------------------ /// <summary> /// Creates a sHow to connect my c# backend with the frontend?Hello, I created a ASP NET Core Web Api project with the command dotnet new webapi -minimal. In my ✅ Using `Func<ReadOnlySpan<char>,bool>` but not allowed due to Pointer TypeI am building a parser, and performance is of concern. So instead of allocating infinite strings wheconcurrency and atomicity Asp.net core web api and efcorelet's say there's an endpoint called AssingUser() ,this endpoint assigns one donation to this currenBuilding a generic repository for mongodbhello folks I was thinking build a generic repository structure for mongodb. but someday if i want Reading large xml file from archive by using XmlReader in Parallel modeHello 👋. I am looking for how can I read data from archive xml file in Parallel mode. I have archiResizing the Console window - Console ApplicationHi there, I'm trying to resize the console window in a Console Application. I have tried multiple ✅ Creating a datetime with a timezoneHow do I create a `DateTime` with `new DateTime(2010, 05, 12);` and give it a specific `TimeZoneInfoCustom Newtonsoft JSON deserializationI have a dictionary where: - The key will always be a string - The value will be either: - string Issue with Form.Close() in WinformsI have a custom form called CustomMessageBox In that form, I have a method that defines a button clIssue with IMGUI.Net.Hello, I am creating an ImGUI application and It doesn't let me move the ui across my entire screen,Issue with deserializing Enums in saved JSONHey, I've been trying to deserialize a list of cards I serialized in C#, the issue I'm having is it From HttpClient, can I save/copy the request to share with someone?Is there a way to copy raw request details? For example, I'm looking for a similar output like: -3D Unity RaycastingHi guys, currently working on a puzzle game involving lasers and mirrors, however, have hit a brick Computer Science - Computer ArchitectureOn a 64 bit system (where the bus length and word size are 64 bits) how would we determine the ammouConnecting SQLite in MAUIHow to connect the database without absolute path? If with it, the program works only on the computeDifferent HttpClient headersWhen I make an HTTP request in my browser (Chrome), I get different response headers than I do in myHttpRequestException:An error occurred while sending the request. WebExceptionHttpRequestException:An error occurred while sending the request. WebException:Unable to connect to ✅ EF does not put datetimes properly to the datebaseI am writing a backend app in asp.net core. This is my service code : ```c# public virtual async TaShadow Prop Error with IdentityDbContextThis is my IdentityDbContext: public class ApplicationUser : IdentityUser { [Required(ErrorMess