当我按下按钮时,appbarbutton和滑块不会隐藏。 当我调试我可以确认已通知“崩溃或可见”。 不知道我做了什么错。请帮助解决问题。
我正在为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 :(得分:0)
没有显式指定源对象的绑定要求目标元素的DataContext
(或其父元素之一)绑定到拥有绑定源属性的类的实例。
因此,将DataContext = this;
添加到构造函数中可以解决问题。