Quantcast
Channel: Caliburn.Micro: Xaml Made Easy
Viewing all articles
Browse latest Browse all 1760

New Post: Message.Attach within DataTemplate

$
0
0

I've got the following (simplified) setup:

<DataGridName="Users"AutoGenerateColumns="False"><DataGrid.Columns><DataGridTemplateColumnHeader="Actions"><DataGridTemplateColumn.CellTemplate><DataTemplate><Menu><MenuItem><!-- This is where the fun begins... --><MenuItemHeader="Suspend"DataContext="{Binding Item, RelativeSource={RelativeSource FindAncestor, AncestorType=DataGridRow}}"cal:Action.TargetWithoutContext="{Binding DataContext, ElementName=Users}"cal:Message.Attach="SuspendUser($dataContext)"/><!-- Other MenuItems omitted --></MenuItem></Menu></DataTemplate></DataGridTemplateColumn.CellTemplate></DataGridTemplateColumn></DataGrid.Columns></DataGrid>

As you can see, the 'Action' column in my DataGrid contains a Menu, with a bunch of items on it. I'm binding these items to an action method on my ViewModel (not on the model present in the row!). In this example, I've got two methods on my ViewModel which look like this:

public Boolean CanSuspendUser(UserModel user)publicvoid SuspendUser(UserModel user)

The problems:

For each and every item, I'm having to specify the DataContext, the Target to invoke the actions on, and a manual message attachment. This makes for a lot of XAML.

Also, my guard methods are never called.

So, my question is...
Any ideas on how to do the above either with less 'fluff', or (ideally) in a better way entirely!

 

Thanks :)


Viewing all articles
Browse latest Browse all 1760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>