5

Tôi nghĩ rằng điều này có một câu trả lời nhỏ nhưng tôi không nhận được nó. Về cơ bản tôi có một ứng dụng Windows Phone 8 có chứa một Pivot và thanh ứng dụng. Tôi muốn ẩn thanh ứng dụng khi một trang nhất định trong Pivot được điều hướng đến.Làm cách nào để ẩn thanh ứng dụng trên các trang Pivot nhất định trong Windows Phone 8

Những gì tôi đã làm là thêm đoạn mã sau trong Pivot_SelectionChanged sự kiện:

AppBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2); 

Vì vậy, khi trang thứ 3 được hiển thị, Application Bar là ẩn, và sẽ được hiển thị khi trang thứ 3 được hướng khỏi . Tuy nhiên, khi tôi chạy ứng dụng, tôi nhận được lỗi NullReference cho AppBar.

tôi cố gắng đặt nó bên trong Dispatcher.BeginInvoke:

Dispatcher.BeginInvoke(() => {  
     AppBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2); 
}); 

Nó hoạt động trong vài thao tác vuốt đầu tiên, nhưng trên gây ra một ngoại lệ NullReference trên trang thứ ba.

Tôi có hoàn toàn theo dõi sai hoặc có cách nào dễ dàng hơn để thực hiện việc này không?

+0

xem http://stackoverflow.com/questions/6007721/is-it-possible-to-show-application-bar-for-one-pivot-item-only – Vovich

+0

@Vovich ah vâng tôi thấy bài đăng đó . tuy nhiên, tôi không nhận ra rằng ApplicationBar không phải là tên do người dùng định nghĩa. Và tôi cũng nghĩ có một cách khác (và khác) để thực hiện điều này trong WP8. Nhưng cảm ơn vì đã chỉ ra điều đó! – Devmonster

Trả lời

9

Không sử dụng tên do bạn đến ApplicationBar, sử dụng ApplicationBar tài sản của trang thay vì:

ApplicationBar.IsVisible = !((((Pivot)sender).SelectedIndex) == 2); 

tức Thay AppBar với ApplicationBar

+0

Đơn giản như vậy. Cảm ơn bạn! – Devmonster

1

Bạn có thể tạo thanh ứng dụng cho các mục pivot nhất định của trang xoay vòng như thế này bằng id.If id = 0, nó sẽ tự động lấy trang trụ 0.Dont quên sử dụng appBarUtils.Bạn có thể tìm thấy here .Bằng cách sử dụng tính năng này, bạn có thể chọn tất cả các thanh công cụ phải nằm trong toàn bộ trang tổng hợp và trong các trang tổng hợp có chọn lọc.

<phone:Pivot> 
    <i:Interaction.Triggers> 
     <appBarUtils:SelectedPivotItemChangedTrigger> 
      <appBarUtils:SelectedPivotItemChangedTrigger.SelectionMappings> 
       <appBarUtils:SelectionMapping SourceIndex="0" TargetIndex="0"/> 
      </appBarUtils:SelectedPivotItemChangedTrigger.SelectionMappings> 

      <appBarUtils:SwitchAppBarAction> 
       <appBarUtils:AppBar Id="0" BackgroundColor="{StaticResource AppBarBg}" ForegroundColor="{StaticResource Foreground}"> 
        <appBarUtils:AppBarButton IconUri="/Assets\Images\appbar.home.png" Text="home" Command="{Binding HomeNavigationCommand}"/> 
       </appBarUtils:AppBar> 

       <appBarUtils:AppBar Id="1" BackgroundColor="{StaticResource AppBarBg}" ForegroundColor="{StaticResource Foreground}"> 
        <appBarUtils:AppBarButton IconUri="/Assets\Images\appbar.home.png" Text="home" Command="{Binding HomeNavigationCommand}"/> 
       </appBarUtils:AppBar> 

       <appBarUtils:AppBar Id="2" BackgroundColor="{StaticResource AppBarBg}" ForegroundColor="{StaticResource Foreground}"> 
        <appBarUtils:AppBarButton IconUri="/Assets\Images\appbar.home.png" Text="home" Command="{Binding HomeNavigationCommand}"/> 
        <appBarUtils:AppBarButton IconUri="/Assets\Images\appbar.money.png" Text="collection" Command="{Binding CollectionPageCommand}"/> 
        <appBarUtils:AppBarButton IconUri="/Assets\Images\appbar.check.rest.png" Text="ok" Command="{Binding OrderConfirmationButtonCommand}"/> 
       </appBarUtils:AppBar> 

       <appBarUtils:AppBar Id="3" BackgroundColor="{StaticResource AppBarBg}" ForegroundColor="{StaticResource Foreground}"> 
        <appBarUtils:AppBarButton x:Name="ConfirmationAppBarButton" IconUri="/Assets\Images\appbar.cancel.rest.png" Text="cancel" Command="{Binding OrderCancelButtonCommand}"/> 
        <appBarUtils:AppBarButton IconUri="/Assets\Images\appbar.check.rest.png" Text="ok" Command="{Binding OrderConfirmationButtonCommand}" IsEnabled="{Binding Model.EnableCheck,Mode=TwoWay}" /> 
       </appBarUtils:AppBar> 

      </appBarUtils:SwitchAppBarAction> 
     </appBarUtils:SelectedPivotItemChangedTrigger> 
    </i:Interaction.Triggers> 
</phone:Pivot> 
0

Đây là phần mở rộng thanh ứng dụng thực sự tuyệt vời cho khung Caliburn.micro. Nó sẽ cho phép bạn xử lý khả năng hiển thị thanh ứng dụng và cấu trúc từ ViewModel, không phải Code-behind.

https://github.com/kamranayub/CaliburnBindableAppBar

Nếu bạn havent thử nó, tôi sẽ mạnh mẽ khuyên bạn nên dùng một cái nhìn tại Caliburn.micro cho Windows Phone 8. Nó thực sự làm một công việc tuyệt vời đơn giản hóa phát triển WP8.