2014-02-13 43 views
0

我正在寫與棱鏡WPF應用程序,我使用MVVM內,註冊一個地區一個ItemTemplate

現在,我有一個項目控制的圖,我想每個項目有一定的樣子,可以選擇爲每個項目添加一個獨特的上下文菜單。 所以它看起來是這樣的,到目前爲止:

<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> 

正如我在代碼中寫的,我想在上下文菜單作爲一個獨特的名字的區域進行註冊(每個裝置持有者對象我想添加一個不同的上下文菜單基於他的類型)。

有沒有辦法做到這一點?

謝謝。

回答

1

我不知道你可以使用ContextMenu作爲一個區域 - 你每天都會學到新的東西!

無論如何,請嘗試以下操作: -

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

我還沒有試過運行它,但VS XAML編輯器不抱怨的語法,這是一個良好的開端。