2017-04-19 8 views
-1

アイテムのリストにバインドされたキャンバスがあります。各アイテムには、それぞれ独自のXフィールドとYフィールドがあり、キャンバスに長方形としてペイントされます。複数のパラメータをviewmodelに渡すContextMenu

各アイテムには、この場合Listにバインドされ、動的に入力されるコンテキストメニューがあります(「オン」、「オフ」など)。

私は現在、送信者(コンテキストメニューが割り当てられている項目)とバインディングの文字列をCommandParameterとしてビューモデルに渡そうとしています。

例:itemA、 "On"

どうすればよいですか?不明であるか:-)を便利ではない質問をする程度

  <ItemsControl 
       x:Name="Overlay" 
       Grid.Column="1" 
       GCextAp:Dragging.IsDragging="{Binding IsDragging, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" 
       ItemsSource="{Binding Path=MapElements, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"> 

       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <Canvas 
          localAp:MapProperties.GenerateMapElementFunc="{Binding CreateMapElementFunc}" 
          localAp:MapProperties.IsEditingMode="{Binding IsEditMode}" 
          localAp:MapProperties.ManipulationFinished="{Binding ManipulationFinishedDelegate}" 
          localAp:MapProperties.ScaleFactor="{Binding ElementName=Overlay, Path=DataContext.ScaleFactor}" 
          AllowDrop="True" 
          RenderOptions.BitmapScalingMode="LowQuality"> 

          <Canvas.Style> 
           <Style TargetType="Canvas"> 
            <Setter Property="Effect"> 
             <Setter.Value> 
              <DropShadowEffect 
               BlurRadius="8" 
               Direction="270" 
               ShadowDepth="2.5" 
               Color="#DDDDDD" /> 
             </Setter.Value> 
            </Setter> 
            <Setter Property="Opacity" Value="1" /> 
            <Setter Property="Background" Value="{x:Null}" /> 
            <Style.Triggers> 
             <MultiDataTrigger> 
              <MultiDataTrigger.Conditions> 
               <Condition Binding="{Binding ElementName=Overlay, Path=(GCextAp:Dragging.IsDragging)}" Value="true" /> 
               <Condition Binding="{Binding IsEditMode}" Value="true" /> 
              </MultiDataTrigger.Conditions> 
              <Setter Property="Background" Value="WhiteSmoke" /> 
              <Setter Property="Opacity" Value="0.1" /> 
             </MultiDataTrigger> 

            </Style.Triggers> 
           </Style> 
          </Canvas.Style> 
          <i:Interaction.Behaviors> 
           <localBehave:MapCanvasDropBehavior /> 
          </i:Interaction.Behaviors> 
         </Canvas> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
       <ItemsControl.ItemContainerStyle> 
        <Style TargetType="ContentPresenter"> 
         <Setter Property="Canvas.Left" Value="{Binding DynamicX}" /> 
         <Setter Property="Canvas.Top" Value="{Binding DynamicY}" /> 
        </Style> 
       </ItemsControl.ItemContainerStyle> 
       <ItemsControl.ItemTemplate> 
        <DataTemplate> 

         <Rectangle 
          Width="{Binding DynamicWidth}" 
          Height="{Binding DynamicHeight}" 
          Stroke="Black" 
          Tag="{Binding DataContext, RelativeSource={RelativeSource AncestorType=Canvas}}" 
          Visibility="{Binding IsVisible, Converter={StaticResource converter}}"> 

          <Rectangle.Fill> 
           <ImageBrush ImageSource="{Binding Image}" /> 
          </Rectangle.Fill> 

          <i:Interaction.Behaviors> 
           <localBehave:MapElementMoveBehavior /> 
          </i:Interaction.Behaviors> 

          <Rectangle.ContextMenu> 
           <ContextMenu> 

            <MenuItem Header="Commands" ItemsSource="{Binding Path=PlacementTarget.Tag.AvailableElementCommands, RelativeSource={RelativeSource AncestorType=ContextMenu}, UpdateSourceTrigger=PropertyChanged}"> 
             <MenuItem.ItemContainerStyle> 
              <Style TargetType="{x:Type MenuItem}"> 
               <Setter Property="Header" Value="{Binding}" /> 
               <Setter Property="Command" Value="{Binding Path=PlacementTarget.Tag.CMD_MapElement, RelativeSource={RelativeSource AncestorType=ContextMenu}}" /> 
               <Setter Property="CommandParameter" Value=" I have no idea" /> 

              </Style> 
             </MenuItem.ItemContainerStyle> 

            </MenuItem> 


           </ContextMenu> 

          </Rectangle.ContextMenu> 

         </Rectangle> 


        </DataTemplate> 
       </ItemsControl.ItemTemplate> 
      </ItemsControl> 

答えて

0

申し訳ありません:

は、ここに私のコードです。とにかく自分で解決策を見つけました。

コマンドのparamaterは次のようになります。

<Setter Property="CommandParameter"> 
                <Setter.Value> 
                 <MultiBinding Converter="{StaticResource menuItemCommandConverter}"> 
                  <MultiBinding.Bindings> 
                   <Binding Path="DataContext" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType=ContextMenu}" /> 
                   <Binding Path="Header" RelativeSource="{RelativeSource Mode=Self}" /> 
                  </MultiBinding.Bindings> 
                 </MultiBinding> 
                </Setter.Value> 
               </Setter> 
関連する問題