微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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 举报,一经查实,本站将立刻删除。