✅ 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.
108 Replies
do you have the source code and screenshots of the issue?
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
I changed the height and still nothing
did u add the styles in the resources?
yes i did in app.axaml
App.axaml needs to have
ok
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
in the documentation it says that it uses MVVM for biding, could it be that?
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
if u have something like this
changes are u already have the MVVM hooked and just didnt know
ok so you only have MVVM set for 1 view
can u show me the code for these 2 files
and
please use the site below to $paste it
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!
post it to the link
pls
easier to read
since its multiple files
ok
or if u have github
u can push and i can check your github too either way works
i pasted it in the link
u click save
then u copy and paste the url
BlazeBin - rndklfgizixx
A tool for sharing your source code with the world!
where is the rest?
its 6 files
oh sorry only read the first messege
but yeah you're not using MVVM you're using code behind
at least for the file u sent in
how do i use mvvm then?
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
https://paste.mod.gg/zuoxcpvvjbwm/4 here are the files
BlazeBin - zuoxcpvvjbwm
A tool for sharing your source code with the world!
did u change in the
i just use the name property
like 'x:Name'
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
no because the mainwindow is meant to be opened first
and from that window you can open other windows
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.
am I blind I dont see where u open it
ok thx let me check
AH
ok found it
it opens from 'dashboard.axaml'
ok yeah so you're writing this as if it was winform
that is not normally how u work with xaml
yes
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
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
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
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
Use the /close command to mark a forum thread as answered
so you can just access the axaml elements directly from c# then?
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
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
that's fair reason why I showed how to apply the DataContext with what u had 😉
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.
what is the error message
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.
did u update your github iwth the latest changes?
that is on the datagrid file right?
yes
are u sure it s up to date?
i've just updated it in github
ok
try cleaning and rebuilding your solution
i get the same error
it does build fine though
it builds without error and fails when u run?
no, it builds and runs fine but when i compile for arm64 linuc in cmd it throws that error
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
but when i don't include the binding it compiles just fine
it is this line: "ItemsSource="{Binding BeurtenGRID}""
QrCode.Net 0.4.0
.Net QrCode Encoder
bad
if that was the case it would not work on windows either
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...
you have a few libraries that do not run on linux
so start by removing those
and elimitate the possibilities
ok
also remove this to avoid confusion as well x:Name="beurtenGrid" since you're not using it
ok
check your Error List for any other warnings about libraries that work on windows only
I think it will be NU.... error
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
github is updated
ok did u remvoe all the libraries that had the issue mentioned in the image above?
think there was 3 or 4
yes, no nuget errors anymore
ok and u still get that binding error on linux?
yes
are u publishing? what options did u select
this is the command:
then u zipped the linux-arm64 folder
and unzipped the whole thing on your linux?
no, i build for linux on my windows pc and move it to linux and than run it on linux
yes but you move the whole fodler with all the files inside of it
not tjust theg exe or dll right
u need all the files inside
yes i do that, but i get an error when compiling it for linux on my windows pc
mmm
so the linux-arm folder doesnt update
ok let me check
ah I think I see the issue moment
ok
open your Desktop csproj
and remove this line
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
yes it worked
👍
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
but how did it manage to run on windows then?
¯\_(ツ)_/¯
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?
yes, and pretty fast
nice to know I have one myself but never ran avalonia on it
so its all working now?
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
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
yes but then the margin top is too big, so i'll just use stackpanel width datagrid on fixed height
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
yes that worked
👍
thanks for your help (again)!
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
ok, i will definitely look into that