문제

나는 mvvmcross 및 mvvm 아키텍처에 상대적으로 새로운 것입니다.

코드를 클릭 할 때 CodeBehind를 가능한 한 깨끗하게 유지하려고 시도하고 항목을 클릭 할 때 명령을 트리거했습니다.

<views:MvxStorePage.Resources>
        <core:Theme x:Key="Theme"/>
        <b:NameScopeBinding  x:Key="ModuleGridView" Source="{Binding ElementName=ModuleGridView}" />
</views:MvxStorePage.Resources>
...
<GridView x:Name="ModuleGridView" >
...
<Interactivity:Interaction.Behaviors>
     <Core:EventTriggerBehavior EventName="SelectionChanged">
          <Core:InvokeCommandAction Command="{Binding SelectModuleCommand}" CommandParameter="{Binding Source.SelectedItem, Source={StaticResource ModuleGridView}}" />
     </Core:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
...
</GridView>
.

및 My ViewModel :

MvxCommand<object> _selectModuleCommand;
        public ICommand SelectModuleCommand
        {
            get
            {
                _selectModuleCommand = _selectModuleCommand ?? new MvxCommand<object>((obj) => SelectModule(obj));
                return _selectModuleCommand;
            }
        }

        private void SelectModule(object module)
        {
            var test = 1;
        }
.

문제는 Interactivity:Interaction.Behaviors에 전달 된 객체가 내 뷰 모드가있는 PCL 핵심 프로젝트에서 사용할 수없는 SelectModule 유형입니다.그래서 해당 객체의 ItemClickedEventArgs 속성에 액세스 할 수 없습니다.

나는이 'invokecommandaction '

에서 이것을 사용해 보았습니다.
 <Core:InvokeCommandAction Command="{Binding SelectModuleCommand}" CommandParameter="{Binding Source.SelectedItem.ClickedItem, Source={StaticResource ModuleGridView}}" />
.

그러나 효과가 없지만, 여전히 내 명령에 대한 매개 변수로 ItemClicked를 가져옵니다

도움이 되었습니까?

해결책

invokeCommandAction의 InvaperConverter 속성을 사용하여 해결

<interactivity:Interaction.Behaviors>
                            <icore:EventTriggerBehavior EventName="ItemClick">
                                <icore:InvokeCommandAction Command="{Binding SelectModuleCommand}" InputConverter="{StaticResource ItemClickedConverter}" />
                            </icore:EventTriggerBehavior>
                        </interactivity:Interaction.Behaviors>
.

itemClickedConverter :

public class ItemClickedConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            var args = value as ItemClickEventArgs;

            if (args != null)
                return args.ClickedItem;

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter,
            string language)
        {
            throw new NotImplementedException();
        }
    }
.

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