Replies: 1 comment
-
|
I'm not entirely sure I follow your issue here, I've not tried inheriting from DataGridTemplateColumn but I do see where you're coming from. One thing I do notice that is related to some issues I've had. You have Try redefining those as DirectProperties and see if it helps your binding issue. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I posted this issue on StackOverflow last week here: https://stackoverflow.com/questions/79882936/avaloniaui-datagrid-changing-datacontext-for-binding-to-custom-column
Please let me know if I should submit or tag this issue differently or any more information is needed. I've been working with .net8.0 'net8.0' in visual studio 2022 and have the Avalonia Visual Studio Extension. Avalonia Version is 11.3.9
I'm new to using AvaloniaUI and trying to get my basic needs checked off. I'm having some issues making custom columns for the DataGrid control
By default the DataGridTemplatedControl type as well as any other columns in a grid behave by shifting their DataContext relative to the ItemsSource of the DataGrid when binding things like their 'Binding' property.
For Example, if I set my ItemsSource to be a list of Task objects (List<Task>) then my columns will bind smoothly to singular Task objects like so. Where Name and Priority are properties on the Task type.
This also works with a DataGridTemplatedColumn when it is defined in place like so:
The problem comes when I try to abstract this into a custom class that I want to be able to reuse quickly. In my instance the custom class is a DataGridComboBoxColumn. I've gotten everything working except one final step. I can't bind nicely to the members of the ItemsSource of the DataGrid.
Here is my custom class:
There's some other stuff in there where I wasn't able to bind to my new properties in the 'xaml' or actually 'axaml' for this avalonia stuff, but I sorted that out generating the Element and EditingElement.
Clearly, something is going on behind the scenes so that regular columns bind to members of the grid's ItemsSource, but I'm losing that when I try adding one of my custom columns to a grid like so:
The ItemsSource binding for the Priority column here works, but not the one for SelectedValue2. When I hover over it, I can clearly see that it considers the type being binded to the ViewModel_JobOverview type that is the DataContext for the UserControl this is all taking place on.
I'm wondering if it's my added properties that are the problem. Do I need to somehow specify this changed context for the properties? I'm also aware that this might not be the only or ideal way to make custom controls in Avalonia but have had my issues with TemplatedControl as well. I'm just looking for any way to make writing the XAML smooth so I can make this and other reusable column types as I have in WPF projects previously, sans Avalonia.
Beta Was this translation helpful? Give feedback.
All reactions