Hi,
I'm trying to make a poker app. I'm trying to create variables in an xaml that will change the image source used based on checkbox selection from a subsequent xaml window.
Does anyone know if this is possible and if so, what am I doing wrong?
Any help would be awesome, cheers.
Here is my current script (Just a test not using the full deck of cards yet):
function PokerTableWindow { [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') [xml]$XAML = @' <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Poker" Height="700" Width="1050" Background="White" WindowStartupLocation="CenterScreen"> <Grid Background="#FF00EEFF" RenderTransformOrigin="0.473,0.537"> <Rectangle Fill="#FF058C2E" HorizontalAlignment="Left" Height="650" Margin="251,7,0,0" Stroke="Black" VerticalAlignment="Top" Width="778"/> <Button Name="btnhand" Content="HAND" HorizontalAlignment="Left" Height="150" Margin="5,7,0,0" VerticalAlignment="Top" Width="241" Background="White" BorderThickness="2" FontSize="36" FontWeight="Bold" Foreground="Black" FontFamily="Segoe UI Light"/> <Button Name="btnflop" Content="FLOP" HorizontalAlignment="Left" Height="150" Margin="5,174,0,0" VerticalAlignment="Top" Width="241" Background="#FFFFF8F8" BorderThickness="2" FontFamily="Segoe UI Light" FontSize="36" Foreground="Black" FontWeight="Bold"/> <Button Name="btnturn" Content="TURN" HorizontalAlignment="Left" Height="150" Margin="5,341,0,0" VerticalAlignment="Top" Width="241" Background="White" BorderThickness="2" FontFamily="Segoe UI Light" FontSize="36" FontWeight="Bold"/> <Button Name="btnriver" Content="RIVER" HorizontalAlignment="Left" Height="150" Margin="5,507,0,0" VerticalAlignment="Top" Width="241" Background="#FFFFFDFD" BorderThickness="2" FontFamily="Segoe UI Light" FontSize="36"/> <Image Name="card3pic" HorizontalAlignment="Left" Height="188" Margin="257,236,0,0" VerticalAlignment="Top" Width="149" Source="$card3" Cursor="Arrow"/> <Image Name="card5pic" HorizontalAlignment="Left" Height="188" Margin="567,236,0,0" VerticalAlignment="Top" Width="149" Source="$card5" Cursor="Arrow"/> <Image Name="card4pic" HorizontalAlignment="Left" Height="188" Margin="413,236,0,0" VerticalAlignment="Top" Width="149" Source="$card4" Cursor="Arrow"/> <Image Name="card6pic" HorizontalAlignment="Left" Height="188" Margin="721,236,0,0" VerticalAlignment="Top" Width="149" Source="$card6" Cursor="Arrow"/> <Image Name="card7pic" HorizontalAlignment="Left" Height="188" Margin="875,236,0,0" VerticalAlignment="Top" Width="149" Source="$card7" Cursor="Arrow"/> <Image Name="card1pic" HorizontalAlignment="Left" Height="188" Margin="257,444,0,0" VerticalAlignment="Top" Width="149" Source="$card1" Cursor="Arrow"/> <Image Name="card2pic" HorizontalAlignment="Left" Height="188" Margin="413,444,0,0" VerticalAlignment="Top" Width="149" Source="$card2" Cursor="Arrow"/> </Grid> </Window> '@ $reader=(New-Object System.Xml.XmlNodeReader $xaml) try{$Form=[Windows.Markup.XamlReader]::Load( $reader )} catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit} $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)} $btnhand.Add_Click({$form.Close()}) $card1pic = <Image Name="card1pic" HorizontalAlignment="Left" Height="188" Margin="257,444,0,0" VerticalAlignment="Top" Width="149" Source="$hcard1, $hcard2, $hcard3, $hcard4, $hcard5, $hcard6, $hcard7" Cursor="Arrow"/> $Form.ShowDialog() | out-null } function HeartsSelectionPreFlop { [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework') [xml]$XAML = @' <Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Poker" Height="700" Width="1050" Background="White" WindowStartupLocation="CenterScreen"> <Grid Background="#FF00EEFF" RenderTransformOrigin="0.473,0.537"> <Rectangle Fill="#FF058C2E" HorizontalAlignment="Left" Height="650" Margin="251,7,0,0" Stroke="Black" VerticalAlignment="Top" Width="778"/> <Button Name="btnHEARTS" Content="HEARTS" HorizontalAlignment="Left" Height="150" Margin="5,7,0,0" VerticalAlignment="Top" Width="241" Background="#FFF7FFC8" BorderThickness="2" FontSize="36" FontWeight="Bold" Foreground="#FFFF0101" FontFamily="Segoe UI Light"/> <Button Name="btnDIAMONDS" Content="DIAMONDS" HorizontalAlignment="Left" Height="150" Margin="5,174,0,0" VerticalAlignment="Top" Width="241" Background="#FFFFF8F8" BorderThickness="2" FontFamily="Segoe UI Light" FontSize="36" Foreground="Red" FontWeight="Bold"/> <Button Name="btnSPADES" Content="SPADES" HorizontalAlignment="Left" Height="150" Margin="5,341,0,0" VerticalAlignment="Top" Width="241" Background="White" BorderThickness="2" FontFamily="Segoe UI Light" FontSize="36" FontWeight="Bold"/> <Button Name="btnCLUBS" Content="CLUBS" HorizontalAlignment="Left" Height="150" Margin="5,507,0,0" VerticalAlignment="Top" Width="241" Background="#FFFFFDFD" BorderThickness="2" FontFamily="Segoe UI Light" FontSize="36"/> <Image Name="AceofHearts" HorizontalAlignment="Left" Height="188" Margin="257,22,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\Aceofhearts.png" Cursor="Arrow"/> <Image Name="_3ofHearts" HorizontalAlignment="Left" Height="188" Margin="567,22,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\3ofhearts.png" Cursor="Arrow"/> <Image Name="_2ofHearts" HorizontalAlignment="Left" Height="188" Margin="413,22,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\2ofhearts.png" Cursor="Arrow"/> <Image Name="_4ofHearts" HorizontalAlignment="Left" Height="188" Margin="721,22,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\4ofhearts.png" Cursor="Arrow"/> <Image Name="_5ofHearts" HorizontalAlignment="Left" Height="188" Margin="875,22,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\5ofhearts.png" Cursor="Arrow"/> <Image Name="_8ofHearts" HorizontalAlignment="Left" Height="188" Margin="875,238,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\8ofHearts.png" Cursor="Arrow"/> <Image Name="_7ofHearts" HorizontalAlignment="Left" Height="188" Margin="567,238,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\7ofHearts.png" Cursor="Arrow"/> <Image Name="_6ofHearts" HorizontalAlignment="Left" Height="188" Margin="257,238,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\6ofHearts.png" Cursor="Arrow"/> <Image Name="_9ofHearts" HorizontalAlignment="Left" Height="188" Margin="257,453,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\9ofHearts.png" Cursor="Arrow"/> <Image Name="_10ofHearts" HorizontalAlignment="Left" Height="188" Margin="413,453,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\10ofHearts.png" Cursor="Arrow"/> <Image Name="JackofHearts" HorizontalAlignment="Left" Height="188" Margin="567,453,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\JackofHearts.png" Cursor="Arrow"/> <Image Name="QueenofHearts" HorizontalAlignment="Left" Height="188" Margin="721,453,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\QueenofHearts.png" Cursor="Arrow"/> <Image Name="KingofHearts" HorizontalAlignment="Left" Height="188" Margin="875,453,0,0" VerticalAlignment="Top" Width="149" Source="D:\Documents\Poker\Cards\KingofHearts.png" Cursor="Arrow"/> <CheckBox Name="aceofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="321,215,0,0" VerticalAlignment="Top" Width="18"/> <CheckBox Name="_2ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="477,215,0,0" VerticalAlignment="Top" Width="20"/> <CheckBox Name="_3ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="631,215,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="_4ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="787,215,0,0" VerticalAlignment="Top" Width="20"/> <CheckBox Name="_5ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="939,215,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="_8ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="939,432,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="_7ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="631,432,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="_6ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="319,432,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="_9ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="319,641,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="_10ofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="477,641,0,0" VerticalAlignment="Top" Width="15"/> <CheckBox Name="Jackofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="631,641,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="Queenofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="786,641,0,0" VerticalAlignment="Top" Width="16"/> <CheckBox Name="kingofheartscb" Content="" HorizontalAlignment="Left" Height="19" Margin="940,641,0,0" VerticalAlignment="Top" Width="15"/> </Grid> </Window> '@ $reader=(New-Object System.Xml.XmlNodeReader $xaml) try{$Form=[Windows.Markup.XamlReader]::Load( $reader )} catch{Write-Host "Unable to load Windows.Markup.XamlReader. Some possible causes for this problem include: .NET Framework is missing PowerShell must be launched with PowerShell -sta, invalid XAML code was encountered."; exit} $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $Form.FindName($_.Name)} $btndiamonds.Add_Click({$form.Close()}) $Form.ShowDialog() | out-null }
PokerTableWindow
HeartsSelectionPreFlop
if ($aceofheartscb.ischecked -eq $true){ $hcard1 = "D:\Documents\Poker\Cards\AceOfHearts.png" } if ($_2ofheartscb.ischecked -eq $true){ $hcard2 = "D:\Documents\Poker\Cards\2OfHearts.png" } if ($_3ofheartscb.ischecked -eq $true){ $hcard3 = "D:\Documents\Poker\Cards\3OfHearts.png" } if ($_4ofheartscb.ischecked -eq $true){ $hcard4 = "D:\Documents\Poker\Cards\4OfHearts.png" } if ($_5ofheartscb.ischecked -eq $true){ $hcard5 = "D:\Documents\Poker\Cards\5OfHearts.png" } if ($_6ofheartscb.ischecked -eq $true){ $hcard6 = "D:\Documents\Poker\Cards\6OfHearts.png" } if ($_7ofheartscb.ischecked -eq $true){ $hcard7 = "D:\Documents\Poker\Cards\7OfHearts.png" }
PokerTableWindow