Reputation: 5375
I have a WPF application with Caliburn Micro. On my DataGrid, I have a context menu with two items, which represent two options two select from. How can I add a check mark on the items?
Here is my code:
<DataGrid.ContextMenu>
<ContextMenu >
<MenuItem Header="Treat Invalid Billing Address As Error" cal:Message.Attach="[Event Click] = [Action TreatInvalidBillingAddressAs('Error')]" />
<MenuItem Header="Treat Invalid Billing Address As Warning" cal:Message.Attach="[Event Click] = [Action TreatInvalidBillingAddressAs('Warning')]" />
</ContextMenu>
</DataGrid.ContextMenu>
...
public void TreatInvalidBillingAddressAs(string errorOrWarning)
{
SelectedFirstEntry.BillingAddressValidation = errorOrWarning;
Revalidate();
}
Thanks
Upvotes: 0
Views: 6640
Reputation: 33364
As mentioned in the comments to control checked status of the MenuItem
you could bind MenuItem.IsChecked
property to the BillingAddressValidation
property of your view model.
Since this is a property of view model against each row and ContextMenu
is defiend against whole DataGrid
you can use SelectedFirstEntry
item.
<MenuItem ... IsChecked="{Binding SelectedFirstEntry.BillingAddressValidation, Converter={StaticResource ErrorToBoolConverter}}"/>
Upvotes: 2