New to Powershell and XAML.
I'm trying to setup the content of a Button to read a specific XML file (C:\Folder\Number.xml) Just to have the chance to change the content of a button of my application directly from an XML instead of changing code in Powershell, and also to show some variable information.
I'm getting the content of the xml file with this:
$xmlFilePathLOCAL = 'C:\Folder\Number.xml'
$NumberXml = [xml](Get-Content $xmlFilePathLOCAL)
"Cell1" button should get the content from the Number tag in the XML file:
XML EXAMPLE HERE:
<?xml version="1.0" encoding="utf-16"?>
<data>
<Number>1</Number>
<Vocals>e</Vocals>
<Days>Monday</Days>
<Fruits>Apples</Fruits>
</data>
I tried to set a Binding and multiple things as the following. It didn't give me any error but at the same time the Button is empty:
<Button Name="Cell1" Grid.Row="0" Grid.Column="0" Opacity="1" Background="#808080" FontFamily="Impact" FontSize="30" Foreground="White">
<TextBlock Text="{Binding ElementName=NumberXml, Path=data/Number}" FontSize="60" FontFamily="Impact"/>
</Button>
What I'm doing wrong? Many thanks to all your help!
This is part of the code:
$xmlFilePathLOCAL = 'C:\Folder\Number.xml'
$NumberXml = [xml](Get-Content $xmlFilePathLOCAL)
#Show-Process "overlay"
$inputXML = @"
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Name="Window"
WindowStyle = "None" WindowState="Maximized"
ResizeMode = "NoResize" Title = "overlay" AllowsTransparency = "True" Background = "Transparent" Opacity = "1" Topmost = "True" >
<Grid x:Name = "Grid" Background = "Transparent" ShowGridLines="False" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Button Name="Cell1" Grid.Row="0" Grid.Column="0" Opacity="1" Background="#808080" FontFamily="Impact" FontSize="30" Foreground="White" Content="TEXT TO GET FROM XML FILE"/>
<Button Name="EXIT" Grid.Row="0" Grid.Column="1" Opacity="1" Background="RED" FontFamily="Impact" FontSize="30" Foreground="White" Content="EXIT"/>
</Grid>
</Window>
"@
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
#Read XAML