Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
466 views
in Technique[技术] by (71.8m points)

forms - Xamarin Prism binding same command in multiple views

I've a page view which has TabView and each tabview item is a separate view, containing list.

<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>

In each child view I've enabled pulldown and pulldown command in each view is pointing to the same 'RefreshCommand'. I want RefreshCommand to be called once no matter from which view pulldown was performed.

Problem is that if I have say 5 child views then refresh command is called 5 times. Obviously I could bind 5 different commands which calls the same method, but would be nice if I could reuse same command.

Is this possible?

Edit: added sample of view in each tab. They all are the same except pointing to different 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>
question from:https://stackoverflow.com/questions/65930531/xamarin-prism-binding-same-command-in-multiple-views

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...