Window Storage Applications How do I link the visibility of a panel item?

I have some problems with binding the visibility property of an application panel button. I want to bind the visibility of an application panel button to another element visibility. If another element is visible, the visibility panel is visible.

So here is my code:

<common:LayoutAwarePage.BottomAppBar> <AppBar> <StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <Button Visibility="{Binding ElementName=btnSave, Path=Visibility}" Click="Edit_Click" /> ...(more buttons) </StackPanel> </AppBar> </common:LayoutAwarePage.BottomAppBar> <Button Grid.Row="7" Grid.Column="0" x:Name="btnSave" Content="Save" Style="{StaticResource EditModeButtonStyle}" Click="Save_Click" /> 

I am changing the visibility of btnSave in the code behind and there is no reaction in the visibility of the panel button. I even tried to do the same binding only with the text block, and it worked fine. I also tried to use the converter in the application panel (I even thought I didn’t need it), and I saw that the debugger did not read the converter methods. I saw some people writing similar problems with the panel, but none of the answers help me. Does anyone know how I can do this? (I do not want to use the code to change the visibility of the panel).

+4
source share
1 answer

I suspect that the elements of the application bar do not see the elements of the page, and therefore the binding of elements does not work. I would recommend that you use an independent property that implements the INotifyPropertyChanged interface. Bind this property to the elements for which you want to set visibility.

FROM#

 public sealed partial class BlankPage4 : Page, INotifyPropertyChanged { private Visibility _IsHide; public Visibility IsHide { get { return _IsHide; } set { _IsHide = value; OnPropertyChanged("IsHide"); } } public BlankPage4() { this.InitializeComponent(); DataContext = this; } private void btnHideAll_Click(object sender, RoutedEventArgs e) { IsHide = Visibility.Collapsed; } public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string property) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(property)); } } } 

Xaml

 <Page.BottomAppBar> <AppBar IsSticky="True" IsOpen="True"> <StackPanel Orientation="Horizontal"> <Button x:Name="btnHello" Visibility="{Binding IsHide}" Content="Hello" /> <TextBlock Visibility="{Binding IsHide}" Text="Hello" FontSize="20"/> </StackPanel> </AppBar> </Page.BottomAppBar> <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"> <StackPanel> <Button x:Name="btnSave" Visibility="{Binding IsHide}" Content="Save" /> <Button Content="Hide All" Click="btnHideAll_Click" /> </StackPanel> </Grid> 
+4
source

All Articles