I've been having issues with Caliburn sometimes setting the property on my View Model, but not always triggering the Setter. It appears to be random that it may bind back to my View Model on changing a property in the DataGrid.
When I remove the Virtualization
attribute, it appears to never work at all.
A partial of my SettingsView.xaml
<DataGrid ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
Height="150"
ItemsSource="{Binding AbilitySettingViewModels}"
AutoGenerateColumns="False" VirtualizingPanel.IsVirtualizing="False"
AlternatingRowBackground="WhiteSmoke">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Ability ID" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox cal:Bind.ModelWithoutContext="{Binding}" Text="{Binding Id}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Custom image" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBox cal:View.Context="{Binding}" cal:Bind.ModelWithoutContext="{Binding}" Text="{Binding Image}" ToolTip="Provide a custom image to use for this Ability." />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Ability Border" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<xctk:ColorPicker cal:View.Context="{Binding}" cal:Bind.ModelWithoutContext="{Binding}" ColorMode="ColorPalette" SelectedColor="{Binding Border, Mode=TwoWay}" DisplayColorAndName="True" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Delete" Width="*">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button cal:Action.TargetWithoutContext="{Binding}" Padding="10,6" Content="Delete" cal:Message.Attach="Delete" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
My SettingsViewModel
contains the following property
// AbilitySettingViewModel is a row Item in the DataGrid
public BindableCollection<AbilitySettingViewModel> AbilitySettingViewModels { get; set; }
I have tried all the cal:Bind
and cal:View
options to see if any of them made a difference on each of the individual controls in the <DataTemplate>
but that hasn't seemed to have worked
Originally I just had {Binding ViewModelProperty}
but it wasn't working. Then saw another DataGrid Issue and managed to get the Button triggering the method on my View Model by adding Action.TargetWithoutContext="{Binding}"
. But still no luck on the other properties in the other Columns.
Are there any known issues or work arounds to get caliburn working with DataGrid?
I'm using Caliburn.micro 2.0.2.
Full SettingsView.xaml
here (Gist link)
Full SettingsViewModel.cs
here (Gist link)
Full AbilitySettingViewModel.cs
here (Gist link)
The events are triggering fine on normal settings. When a setting changes, this is getting serialised to a settings.json file perfectly fine. It also seems to be loading the settings.json fine AND even for the Child View Models that get serialised (AbilitySettingsViewModel) they appear to be loaded into the DataGrid with correct values set...just editing them does not work.
using the "Delete" button works fine and serializing removes the item, which is working as expected.
There was no need to try the custom caliburn bindings. All that needed to be set on each was the Path=PROPERTY
.