Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Xaml UWP按钮使用INotifyPropertyChanged隐藏/显示不工作_C#_Xaml_Uwp Xaml - Fatal编程技术网

C# Xaml UWP按钮使用INotifyPropertyChanged隐藏/显示不工作

C# Xaml UWP按钮使用INotifyPropertyChanged隐藏/显示不工作,c#,xaml,uwp-xaml,C#,Xaml,Uwp Xaml,当我按下按钮时,应用程序按钮和滑块不会隐藏。 调试时,我可以确认已通知“折叠或可见”。 不知道我犯了什么错误。请帮助解决此问题 我正在为xbox one构建通用Windows平台(UWP) <Page x:Class="AvProStreaming.MainPage" IsTabStop="false" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.micr

当我按下按钮时,应用程序按钮和滑块不会隐藏。 调试时,我可以确认已通知“折叠或可见”。 不知道我犯了什么错误。请帮助解决此问题

我正在为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>

没有显式指定源对象的绑定要求将目标元素的
DataContext
(或其父元素之一)设置为拥有绑定源属性的类的实例


因此添加
DataContext=this
给构造函数解决了这个问题。

试着明确地设置绑定模式:
{binding IsHide,mode=OneWay}
我添加了模式,但它不起作用。你能在setter方法中添加一个断点并查看它是否得到更新吗?当我在setter中设置断点时,_IsHide值是“折叠”的。但是xaml部分没有升级。如果我在xaml中显式地将可见性设置为collapse,它就会工作。您需要调试并查看是否所有调用都按正确的顺序进行。单击按钮后,应调用setter。在集合中,应调用OnPropertyChanged(…)。财产是否已更改!=null并被提升(对于“IsHide”)?在这之后,应该调用get for IsHide,这是否也在发生?IsHide回来有什么好处?
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;
        }
    }