I'm working with a SplitView application, and I've created a Shell that hosts the subpages. What I'd like to do is have a button on a subpage that when clicked, can manipulate the visibility of objects originally initiated or created on the Shell xaml. But, I'm not sure how to call the class or frame necessary to change attributes on the SplitView.
My hierarchy is as follows: Shell > Pages Folder > Sub Pages
Here's the snippet from my Shell.xaml Mind you this is only a portion contained within the SplitView
<SplitView.Pane>
<StackPanel x:Name="SplitViewPanePanel">
<RadioButton x:Name="BackRadioButton" Click="BackRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Background="Gray" Content="Back" GroupName="Back"/>
<RadioButton x:Name="HamburgerRadioButton"
Click="HamburgerRadioButton_Click"
Style="{StaticResource NavRadioButtonStyle}"
Tag=""
Content="Menu" />
<RadioButton x:Name="HomeRadioButton" Click="HomeRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Home" GroupName="Navigation"/>
<RadioButton x:Name="TARadioButton" Click="MTRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Team Assignments" GroupName="Navigation"/>
<RadioButton x:Name="ASRRadioButton" Click="ASRRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Assignment Switch Requests" GroupName="Navigation"/>
<RadioButton x:Name="MTRadioButton" Click="MTRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Management Tools" GroupName="Navigation"/>
</StackPanel>
</SplitView.Pane>
Below is the code from my "Home" page inside the Pages folder.
using Team_Management_Hub;
using Team_Management_Hub.Pages;
namespace Team_Management_Hub.Pages
{
public sealed partial class Home : Page
{
public Home()
{
this.InitializeComponent();
}
private void TestButton_Click(object sender, RoutedEventArgs e)
{
//Here is the button I want to be able to click to alter the visibility of the MTRadioButton
}
}
}
I've looked for a couple days now for examples or explanations on how to access the parent Shell, and I can't seem to figure it out. It should be noted that this is my first UWP in Windows 10, and I'm fairly new to C#.
Additionally, if it helps or is relevant, the below code is inside the Shell.xaml.cs file that I use to navigate to individual Pages.
private void HomeRadioButton_Click(object sender, RoutedEventArgs e)
{
var frame = this.DataContext as Frame;
Page page = frame?.Content as Page;
if (page?.GetType() != typeof(Home))
{
frame.Navigate(typeof(Home));
}
}
UPDATE: So, I've implemented some changes from the first answer provided, and I seem to have something incorrect with my scope inside the Shell.xaml file.
Here's my Shell.xaml file:
<Page
x:Class="Team_Management_Hub.Shell"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Team_Management_Hub"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:pages="using:Team_Management_Hub.Pages"
mc:Ignorable="d">
<pages:Home MyCoolEvent="OnCoolEvent"/>;
<SplitView x:Name="Team_Management_Hub" Background="Black" OpenPaneLength="240" CompactPaneLength="48"
DisplayMode="CompactOverlay" IsPaneOpen="False" PaneBackground="Gray" Content="{Binding}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="HardwareButtons">
<VisualState.Setters>
<Setter Target="BackRadioButton.Visibility" Value="Collapsed" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<SplitView.Pane>
<StackPanel x:Name="SplitViewPanePanel">
<RadioButton x:Name="BackRadioButton" Click="BackRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Background="Gray" Content="Back" GroupName="Back"/>
<RadioButton x:Name="HamburgerRadioButton" Click="HamburgerRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Menu" />
<RadioButton x:Name="HomeRadioButton" Click="HomeRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Home" GroupName="Navigation"/>
<RadioButton x:Name="TARadioButton" Click="TARadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Team Assignments" GroupName="Navigation"/>
<RadioButton x:Name="ASRRadioButton" Click="ASRRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Assignment Switch Requests" GroupName="Navigation"/>
<RadioButton x:Name="MTRadioButton" Click="MTRadioButton_Click" Style="{StaticResource NavRadioButtonStyle}" Tag="" Content="Management Tools" GroupName="Navigation"/>
</StackPanel>
</SplitView.Pane>
</SplitView>
With this, everything under <pages:Home MyCoolEvent="OnCoolEvent"/>
gets underlined blue, and the error "the property Content is set more than once"
I found this link and so I tried to implement putting it all in a grid, but when I simply add <Grid>
above the <SplitView>
and below the final </SplitView>
if I keep the <pages>
portion above the splitview, the button on the Home.xaml page doesn't do anything. If I move the <pages>
to below the <SplitView>
but still inside the <Grid></Grid>
the button works, but the SplitView disappears. I also tried throwing the <pages>
inside the <StackPanel>
that holds my RadioButtons, but it does something weird, where it appears my Home Page is inside the SplitView Pane under the buttons. So, I'm sure I've got some simple mistake I'm making with the scope of the xaml setup, but I've tried so many combinations of placing the <pages:Home>
in so many different areas and inside different controls, and I haven't gotten it to work. So, some help on the proper layout to make this work, would be great.
Thanks for any help.