Xamarin Prism 在多个视图中绑定相同的命令

问题描述

我有一个包含 TabView 的页面视图,每个 tabview 项目都是一个单独的视图,包含列表。

<TabView>
        <TabViewItem HeaderText="Comments">
            <TabViewItem.Content>
                    <local:CommentsListView/>
            </TabViewItem.Content>
        </TabViewItem>

        <TabViewItem HeaderText="Stock">
            <TabViewItem.Content>
                <local:StockListView/>
            </TabViewItem.Content>
        </TabViewItem>

        <TabViewItem HeaderText="Labour">
            <TabViewItem.Content>
                <local:LabourListView/>
            </TabViewItem.Content>
        </TabViewItem>
</TabView>

在每个子视图中,我启用了每个视图中的下拉和下拉命令指向相同的“RefreshCommand”。无论从哪个视图下拉执行,我都希望 RefreshCommand 被调用一次。

问题是,如果我说 5 个子视图,则调用 5 次刷新命令。显然我可以绑定 5 个调用相同方法的不同命令,但如果我可以重用相同的命令就好了。

这可能吗?

编辑:在每个选项卡中添加了视图示例。除了指向不同的 ItemSource 之外,它们都是相同的:

<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:prism="http://prismlibrary.com"
             prism:viewmodelLocator.Autowireviewmodel="True"
             xmlns:custom="clr-namespace:Controls"
             xmlns:converter="clr-namespace:Converters"
             x:Class="CommentsListView">

    <ContentView.Resources>
        <ResourceDictionary>
            <converter:NegateBooleanConverter x:Key="inverter" />
        </ResourceDictionary>
    </ContentView.Resources>

    <custom:ObjectGridView
        x:Name="commentsListView"
        ItemsSource="{Binding CommentsList}"
        IsPullToRefreshEnabled="{Binding InEditMode,Converter={StaticResource inverter}}"
        IsRefreshing="{Binding IsRefreshing,Mode=TwoWay}"
        PullToRefreshCommand="{Binding RefreshCommand}"
        RowTapCommand="{Binding CommentTapCommand}"
        ShowAddButton="True"
        AddButtonVisible="{Binding InEditMode}"
        AddButtonCommand="{Binding AddButtonCommand}"/>
</ContentView>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)