문제

<MenuItem Command="local:CommandLibrary.RegisterServiceCommand">
    <MenuItem.CommandParameter>
        <MultiBinding Converter="{StaticResource TrayWindowViewModelConverterResource}">
            <MultiBinding.Bindings>
                <Binding ElementName="Me" />
                <Binding FallbackValue="Parser" />
            </MultiBinding.Bindings>
        </MultiBinding>
    </MenuItem.CommandParameter>
</MenuItem>

public class TrayWindowViewModelConverter : IMultiValueConverter {
    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) {
        var viewModel = new Window1ViewModel();

        foreach (var obj in values) {
            if (obj is Window)
                viewModel.Caller = obj as Window;
            else if (obj is string)
                viewModel.ServiceName = obj.ToString();
        }

        return viewModel;
    }

    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) {
        throw new NotImplementedException();
    }
}

Button cammand is exactly same as MenuItem. when i debug Converter for MenuItem, values parameter contains two object: DependencyProperty.UnsetValue (I'm not aware what's this) and MyContextMenu object.

And also how can i pass SomeType as parameter? Thanks

도움이 되었습니까?

해결책

MenuItems exist in popups that are outside the main visual tree and so don't have the same name scope as surrounding elements, like your Button. When trying to bind, the ElementName binding can't resolve because the "Me" element is outside the MenuItem's name scope.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top