Open Ka1Nn opened 2 months ago
Here an update, that how i make it works
You need to declare classes :
class HomePage : System.Windows.Controls.UserControl {
HomePage() {
$this.LoadXamlFromFile()
}
[void] LoadXamlFromFile() {
$xamlPath = "$global:ScriptPath\Views\Pages\Home.xaml"
$xmlDocument = New-Object System.Xml.XmlDocument
$xmlDocument.Load($xamlPath)
$reader = New-Object System.Xml.XmlNodeReader $xmlDocument
$loadedContent = [System.Windows.Markup.XamlReader]::Load($reader)
$this.Content = $loadedContent
}
}
# Class ItemPage using a Grid instead of a Page
class ItemPage : System.Windows.Controls.Page {
ItemPage() {
$this.LoadXaml()
}
[void] LoadXaml() {
$xaml = @"
<Grid xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml'
Width="800" Height="600"
Background='LightBlue'>
<TextBlock Text='Welcome to the Home Page!'
VerticalAlignment='Center'
HorizontalAlignment='Center'
FontSize='24'/>
</Grid>
"@
$stringReader = New-Object System.IO.StringReader($xaml)
$xmlReader = [System.Xml.XmlReader]::Create($stringReader)
$loadedContent = [System.Windows.Markup.XamlReader]::Load($xmlReader)
$this.Content = $loadedContent
}
}
Then initialize like this :
$HomeMenu.TargetPageType = [HomePage]::new().GetType()
$ItemsMenu.TargetPageType = [ItemPage]::new().GetType()
Note :
Please make something easier.. clearer... and usuable... I had never use classes to display a navigationViewItem before...
Describe the bug
I'm trying to use the standard approach in PowerShell WPF for setting up a NavigationViewItem in a FluentWindow. However, it's not working as expected, and the NavigationViewItem appears empty.
Here’s the code I’m using:
To Reproduce
Powershell.ps1
Home.xaml looks like
Expected behavior
The XAML page content should be displayed correctly in the user interface when the corresponding menu item is selected, without requiring a compiled class.
Like i use powershell i'm not able to use TargetPageType Property to fill up the menu content.
the application opens but immediately freezes, making it unusable
Screenshots
OS version
Windows 11 22h2
.NET version
[System.Runtime.InteropServices.RuntimeInformation]::FrameworkDescription returns : .NET Framework 4.8.9261.0
WPF-UI NuGet version
wpf-ui\3.0.5\lib\net481\wpf.ui.dll
Additional context
No response