使用綁定轉換器:
public class CommandParamConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is string)
{
return string.Format("Key {0}", value);
}
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
將它添加到Windows \用戶控件資源:
<Window.Resources>
<local:CommandParamConverter x:Key="commandParamConverter" />
</Window.Resources>
參考它在菜單CommandParameter結合:
<MenuItem Header="Key" CommandParameter="{Binding Converter={StaticResource commandParamConverter}, Path=PlacementTarget.Tag, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/>
您是否將此值發送到命令Parameter? – 2011-06-16 09:57:31