Open previous TabViewItems after page navigation of NavigationView class - c#

I want to save the opened TabViewItems dynamically, so that the user can switch to another page and return to his work, for example.
Problem:

Open previous TabViewItems after page navigation of NavigationView class
If you initialize the TabView's DataSource in the Page ctor, you could set the page's NavigationCacheMode as Required like the following
<Page
x:Class="App19.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:App19"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
Background="Transparent"
NavigationCacheMode="Required"
mc:Ignorable="d">

Related

Navigating between pages in wpf not working

I've done the simplest thing. I open a new window and put a frame in it and I wanted to show in the frame a page.
The window code:
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
Page1 p = new Page1();
navigator.NavigationService.Navigate(p);
}
}
navigator is the frame, in Page1 I have black background color to see the difference. When I run it I still see the window and not the page that should be inside the frame. Why isn't this working?
Window:
Page:
But i get the white one.
The code for page 1:
<Page x:Class="test.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="269" d:DesignWidth="292"
Title="Page1">
<Grid Background="Black">
</Grid>
In the cs side i didn't write anything.
You need to set the Content property of the Page to something to be able to actually see it:
<Page x:Class="test.Page1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="269" d:DesignWidth="292"
Title="Page1">
<Grid Background="Black">
<TextBlock>PAGE1</TextBlock>
</Grid>
</Page>
An empty black Grid is not visible but if you put a TextBlock in it you should be able to see it.

WPF Page Title Bar Hide

I know how to hide the title bar in windows: WindowStyle="none". But how can i achieve that with Pages?
I have a code like this:
<Page x:Class="SomeNamePage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:local="SomeName"
mc:Ignorable="d"
d:DesignHeight="700" d:DesignWidth="700" WindowHeight="700" WindowWidth="700"
Title="Page1" Background="#FFFFFF">
How can i hide the title bar with the same results as WindowStyle="None"?
I figured out that's not possible. I solved using a Window as holder for the navigation menu and a frame that switches between Pages for the content.
Hope this helps others!

UserControl content can't be set more than once

having some troubles with UserControl. I cannot get rid of "Content is set more than once error"
From what I've read, the common cause is that .. well, content is set more than once. For example having more than one child or setting content via Content=".." and then specifying another content between the tags.
However, this is UserControl generated by VisualStudio and I made no changes to the xaml.
<UserControl x:Class="TMEGadget.View.Toolbox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
</Grid>
</UserControl>
Got any tips?
P.S: Can anyone tell me why, when I try to type "Hey,\n\nSome text...", the "Hey,\n\n" is deleted?
Edit: Restarting VS fixed the problem , thanks #Bolu

Access a UserControl from code in WPF app

I have a created a usercontrol in my wpf application. I have used it like so:
<Page x:Class="InstallerToolkit.Pages.PageVideosNvr"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:my="clr-namespace:MyProject.UserControls"
mc:Ignorable="d"
d:DesignHeight="525" d:DesignWidth="1050"
Title="PageVideos">
<Grid>
<my:UserControlVideoPlayer Name="VideoPlayer" Margin="559,74,35,155">
</my:UserControlVideoPlayer>
</Grid>
Now in my C# page I want to access it but the VideoPlayer object doesnt appear when I type its name in the code behind c# page.
What doo I do to access it as I want to set one of its properties.
Give x:Name to your UserControl instead of Name
<my:UserControlVideoPlayer x:Name="VideoPlayer" Margin="559,74,35,155">
It will be accessible now in code behind using this.VideoPlayer.
I would suggest to make it a thumb rule that always use x:Name whenever referring to elements in XAML.
Refer to this for difference between Name and x:Name.

Can't access Windows 8 Store user control from code

I'm writing a Windows 8 Store application and within that I've designed my own user control.
Here is the code for my usercontrol (This is a dummy control but the problem exists with this):
<UserControl
x:Class="Windows8StoreTest.TestUserControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Width="70"
Height="40">
<StackPanel>
<Button Content="Hello" Foreground="Pink" BorderBrush="Pink"/>
</StackPanel>
</UserControl>
I've dropped the user control onto my page and give it a name:
<Page
x:Class="Windows8StoreTest.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Windows8StoreTest"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:TestUserControl Name="testControl"/>
</Grid>
</Page>
However, when I go to the code behind I can't access the control by that name. It doesn't seem to exist! What is weird is that the control doesn't exists within InitializeComponent() method for the MainPage class which will be why it does exist.
What am I missing from my user control?
I'm using Windows 8 Store, XAML, c#.
Thanks in advance
Try to use this:
<local:TestUserControl x:Name="testControl"/>
Should work...
hello i don't know what is wrong but it should work.i have just made a sample example of it..i am putting it here hope you have done the same way.
<Page
x:Class="App12.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App12"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<local:MyUserControl1 x:Name="hellousercontrol" />
</Grid>
in my mainpage.cs.. i have just use it like this..
public MainPage()
{
this.InitializeComponent();
hellousercontrol.Height = 100;
}
one more this..have build your solution ?
I had the same issue in c++ environment. I observed, I didn't had default constructor in my class, as soon as I added the default constructor, I could use the defined UserControl in my project through XAML file. However without default constructor I was able to use it from within c++ code.

Categories

Resources