2017-02-09 79 views
0

當我按下按鈕時,appbarbutton和滑塊不會隱藏。 當我調試我可以確認「崩潰或可見」已通知。 不知道我做了什麼錯誤。請幫助解決問題。Xaml UWP按鈕隱藏/顯示不工作使用INotifyPropertyChanged

我正在爲xbox one的通用Windows平臺(UWP)構建。

<Page 
x:Class="AvProStreaming.MainPage" 
IsTabStop="false" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:AvProStreaming" 
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
mc:Ignorable="d" 
Background="RosyBrown"> 

<SwapChainPanel x:Name="DXSwapChainPanel"> 
    <Grid x:Name="ExtendedSplashGrid" Background="#FFFFFF"> 
     <Image x:Name="ExtendedSplashImage" Source="Assets/SplashScreen.png" VerticalAlignment="Center" HorizontalAlignment="Center"/> 
    </Grid> 

    <Slider x:Name="slider" Background="Cyan" HorizontalAlignment="Stretch" Margin="10,444,10,0" VerticalAlignment="Top" Height="46" 
      Visibility="{Binding IsHide}" /> 

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Bottom" Height="150" > 

     <AppBarButton Foreground="Cyan" Icon="Back" Name="Backward" Label="Back" Click="MenuItem_Selected" 
        Visibility="{Binding IsHide}" Margin="30"/> 
     <AppBarButton Foreground="Cyan" Icon="Play" Name="Play" Label="Play" Click="MenuItem_Selected" 
        Visibility="Collapsed" Margin="30"/> 
     <AppBarButton Foreground="Cyan" Icon="Pause" Name="Pause" Label="Pause" Click="MenuItem_Selected" 
        Visibility="{Binding IsHide}" Margin="30"/> 
     <AppBarButton Foreground="Cyan" Icon="Forward" x:Name="Forward" Label="Forward" Click="MenuItem_Selected" 
        Visibility="{Binding IsHide}" Margin="30"/> 

    </StackPanel> 

</SwapChainPanel> 

public sealed partial class MainPage : Page, INotifyPropertyChanged 
{ 
    private WinRTBridge.WinRTBridge _bridge; 

    private SplashScreen splash; 
    private Rect splashImageRect; 
    private WindowSizeChangedEventHandler onResizeHandler; 

    private Visibility _IsHide; 
    public Visibility IsHide 
    { 
     get { return _IsHide; } 
     set 
     { 
      _IsHide = value; 
      OnPropertyChanged("IsHide"); 
     } 
    } 
    public event PropertyChangedEventHandler PropertyChanged; 

    private void OnPropertyChanged(string property) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(property)); 
     } 
    }...... 

private void MainPage_KeyDown(object sender, KeyRoutedEventArgs e) 
    { 
     Debug.WriteLine("Keydown"); 

     if (!App.IsXbox()) 
      e.Handled = true; 

     if (e.OriginalKey == Windows.System.VirtualKey.GamepadMenu) 
     { 
      Debug.WriteLine("GamepadView button clicked"); 
      IsHide = Visibility.Collapsed; 
     } 
    } 
+0

嘗試明確地設置綁定模式:{{Binding IsHide,Mode = OneWay}' –

+0

我添加了模式,但它沒有工作plz – Muniraj

+0

您可以在setter方法中添加一個斷點並查看它是否正在更新? – AbsoluteSith

回答

0

綁定而無需明確指定的源對象需要目標元素的DataContext(或它的父元素中的一個的)被設置爲類的實例的擁有綁定源屬性。

因此,將DataContext = this;添加到構造函數中解決了問題。