BindableApplicationBar ไม่เริ่มเหตุการณ์การแตะ

ฉันต้องการ ApplicationBar ที่สามารถผูกไว้กับทั้งคำสั่งและเหตุการณ์การแตะ (จำเป็นต้องมีเหตุการณ์การแตะสำหรับสิ่งที่เกี่ยวข้องกับ UI และฉันไม่สามารถจัดการได้ในโมเดลของฉัน)

ฉันกำลังลองใช้ BindableApplicationBar จาก NuGet และการผูกคำสั่งทำงานได้ดี แต่ไม่มีวิธีรับเหตุการณ์การแตะ

โปรดทราบว่าฉันกำลังเปลี่ยน DataContext เพื่อให้การเชื่อมโยงใช้งานได้ แต่เหตุการณ์ Tap จะต้องได้รับการจัดการในโค้ดที่อยู่เบื้องหลัง (และฉันไม่รู้ว่านี่อาจเป็นสาเหตุหลักของปัญหาของฉันหรือไม่!)

นี่คือ xaml ของบาร์:

<bindableApplicationBar:Bindable.ApplicationBar>
    <bindableApplicationBar:BindableApplicationBar>
        <bindableApplicationBar:BindableApplicationBarButton
            Text="{Binding MainSearchText}"
            IconUri="Assets/AppBar/feature.search.png"
            Command="{Binding NavigateCommand}"
            Name="SearchBarButton" />
        <bindableApplicationBar:BindableApplicationBarButton
            Text="{Binding Path=LocalizedResources.AppBarSettingsText, Source={StaticResource LocalizedStrings}}"
            IconUri="Assets/AppBar/feature.settings.png"
            Tap="SettingsButton_OnTap" />
        <bindableApplicationBar:BindableApplicationBar.MenuItems>
            <bindableApplicationBar:BindableApplicationBarMenuItem
                Text="{Binding Path=LocalizedResources.AppBarAboutText, Source={StaticResource LocalizedStrings}}"
                Tap="Info_OnTap" />
        </bindableApplicationBar:BindableApplicationBar.MenuItems>
    </bindableApplicationBar:BindableApplicationBar>
</bindableApplicationBar:Bindable.ApplicationBar>

และนี่คือหนึ่งในตัวจัดการที่ฉันมีในไฟล์ .xaml.cs:

private void Info_OnTap(object sender, GestureEventArgs e)
{
    _about.Show();
    Debug.WriteLine("INFO ON_TAP");
}

ไม่มีการเขียนบรรทัด "INFO ON_TAP" เมื่อฉันคลิกที่ MenuItem

มีอะไรผิดปกติกับมัน?


person StepTNT    schedule 02.10.2013    source แหล่งที่มา
comment
ถ้าคุณใส่เบรกพอยต์เป็นวิธีการของคุณ คุณจะผ่านไหม?   -  person MatDev8    schedule 03.10.2013
comment
ใช่แล้ว วิธีการนี้ไม่ได้ถูกเรียกด้วยซ้ำ   -  person StepTNT    schedule 03.10.2013
comment
ทำไมคุณไม่ใช้การคลิกหรือคำสั่ง? และฉันคิดว่าเมื่อคุณแตะปุ่ม มันใช้งานไม่ได้แต่ถ้าแตะบนหน้าจอก็ผ่านใช่ไหม?   -  person MatDev8    schedule 03.10.2013


คำตอบ (2)


นี่ไม่ใช่วิธีที่คุณจะใช้ BindableApplicationBar BindableApplicationBarButton สืบทอดมาจาก FrameworkElement (และมีเหตุการณ์ Tap) เพื่อรองรับ DataContext และ Bindings เหตุการณ์ Tap ไม่ได้เริ่มทำงานเนื่องจากไม่มีการแตะ BindableApplicationBarButton เลย ไม่มี BindableApplicationBarButton ปรากฏบนหน้าจอ - นี่เป็นเพียง wrapper ที่สร้าง ApplicationBarIconButton แต่จะไม่ส่งผ่านตัวจัดการเหตุการณ์ Tap ไปที่มัน (ApplicationBarIconButton มีเพียงอันเดียวเท่านั้น กิจกรรม - คลิก) เช่นเดียวกับ BindableApplicationBarMenuItem BindableApplicationBar ทำงานได้ดีที่สุดกับคำสั่ง

ดูเพิ่มเติมในความคิดเห็นในแหล่งที่มา: BindableApplicationBar @ codeplex

นี่คือตัวเลือกของคุณ (บางส่วน):

  • ใช้คุณสมบัติคำสั่งของ BindableApplicationBarButton เพื่อตอบสนองต่อการคลิกปุ่ม
  • หลังจากกำหนด BindableApplicationBar ใน xaml แล้ว ให้เชื่อมต่อเพื่อคลิกเหตุการณ์ของ ApplicationBarIconButtons ที่สร้างขึ้นใน โค้ดด้านหลัง
  • ใช้โค้ด BindableApplicationBar (โอเพ่นซอร์ส) และแก้ไขเพื่อประสบการณ์ที่ดีที่สุดในฉากของคุณ
person lisp    schedule 04.10.2013

คุณสามารถลองใช้ Cimbalino Toolkit AppBar ... มีประสิทธิภาพและใช้งานง่ายกว่ามาก!

ตัวอย่างเช่น:

 <i:Interaction.Behaviors>
        <cimbalinoBehaviors:MultiApplicationBarBehavior 
            SelectedIndex="{Binding SelectedIndex, ElementName=MainInfo, Converter={StaticResource HomeMenuConverter}}" >

            <cimbalinoBehaviors:ApplicationBar Opacity="0.5"  
                                               IsMenuEnabled="{Binding IsLoading, Converter={StaticResource NegativeBooleanConverter}}">


                <cimbalinoBehaviors:ApplicationBarIconButton 
                    IsVisible="{Binding IsAuthenticated}"
                    IsEnabled="{Binding IsLoading, Converter={StaticResource NegativeBooleanConverter}}"
                    Command="{Binding GetFavorites, Mode=OneTime}" 
                    IconUri="/Assets/appbar.sync.rest.png" Text="{Binding Labels.Translation.Refresh, Source={StaticResource LabelsManager}}" />
                <cimbalinoBehaviors:ApplicationBarIconButton 
                    IsVisible="{Binding SelectionMode, Converter={StaticResource NegativeBooleanConverter}}"
                    IsEnabled="{Binding IsLoading, Converter={StaticResource NegativeBooleanConverter}}"
                    Command="{Binding SetSelectionMode, Mode=OneTime}" 
                    IconUri="/Assets/ApplicationBar.Select.png" Text="{Binding Labels.Translation.Select, Source={StaticResource LabelsManager}}" />
                <cimbalinoBehaviors:ApplicationBarIconButton 
                    IsVisible="{Binding SelectionMode}"
                    IsEnabled="{Binding IsLoading, Converter={StaticResource NegativeBooleanConverter}}"
                    Command="{Binding DeleteFavorites, Mode=OneTime}" 
                    IconUri="/Assets/ApplicationBar.Delete.png" Text="{Binding Labels.Translation.Delete, Source={StaticResource LabelsManager}}" />

                <cimbalinoBehaviors:ApplicationBarIconButton 
                    IsVisible="{Binding SelectionMode}"
                    IsEnabled="{Binding IsLoading, Converter={StaticResource NegativeBooleanConverter}}"
                    Command="{Binding SetSelectionMode, Mode=OneTime}" 
                    IconUri="/Assets/ApplicationBar.Cancel.png" Text="{Binding Labels.Translation.Cancel, Source={StaticResource LabelsManager}}" />

            </cimbalinoBehaviors:ApplicationBar>
        </cimbalinoBehaviors:MultiApplicationBarBehavior>
    </i:Interaction.Behaviors>

https://github.com/Cimbalino/Cimbalino-Phone-Toolkit

person Cristovao Morgado    schedule 23.10.2013