Question

I'm writing a WPF application with Prism and I'm using MVVM,

Now, I have a view with Items Control, and I want each item to have a certain look, with an option to add a unique context menu per item. so it look's like this so far:

<ItemsControl Grid.Column="1" ItemsSource="{Binding DeviceHolders}">
  <ItemsControl.ItemTemplate>
     <DataTemplate>
         <Grid>
            <Image Name="image" Source="{Binding ImageIndex, Converter={StaticResource ImageIndexToLargeImageBitmapSource}}" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Center">
               <Image.ContextMenu>
                      <ContextMenu <--THIS AS A UNIQUE REGION WHICH THE REGION NAME WILL BE string.format("{0}-{1}", "DeviceHolderRegion", DeviceHolder.ID)-->/>
               </Image.ContextMenu>
            </Image>
         </Grid>
      </DataTemplate>
  </ItemsControl.ItemTemplate>
</ItemsControl>

As I wrote in the code, I want the context menu to register as a region with a unique name (for each device holder object I want to add a different context menu based on his type).

is there a way to do so?

Thanks.

Was it helpful?

Solution

I didn't know you could use a ContextMenu as a region - you learn something new every day!

Anyway, try the following:-

<ContextMenu>
    <regions:RegionManager.RegionName>
        <MultiBinding StringFormat="{}{0}-{1}">
            <Binding Path="DeviceHolderRegion" />
            <Binding Path="DeviceHolder.ID" />
        </MultiBinding>
    </regions:RegionManager.RegionName>
</ContextMenu>

I haven't tried running it, but VS XAML editor doesn't complain about the syntax, which is a promising start.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top