XAML re-visited

Started by spl, August 29, 2024, 01:50:57 PM

Previous topic - Next topic

spl

These GUI's are just so easy to create. The WB code below will display for 5 seconds. I thought there was some interest in XAML with WB.
XAML = $"
    <Window
        xmlns="http:://schemas.microsoft.com/winfx/2006/xaml/presentation"
        Title="Password Generator" Height="317.01" Width="704.124" ResizeMode="NoResize">
        <Grid>
            <Label Content="Password Length" HorizontalAlignment="Left" Margin="36,31,0,0" VerticalAlignment="Top" RenderTransformOrigin="-2.568,-2.973" Height="34" Width="140" FontSize="16" FontFamily="Trebuchet MS"/>
            <TextBox Name="Plengthtxtbox" HorizontalAlignment="Left" Height="28" Margin="181,37,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="88" RenderTransformOrigin="0.503,-0.152" Background="##FFF9F9F9"/>
            <Button Name="Generatebtn" Content="Generate" HorizontalAlignment="Left" Margin="295,37,0,0" VerticalAlignment="Top" Width="140" Height="28" Background="##FF78CB87"/>
            <Label Content="New Generated Password" HorizontalAlignment="Left" Margin="36,99,0,0" VerticalAlignment="Top" Width="194" Height="37" FontSize="16"/>
            <TextBox Name="Pouttxtbx" HorizontalAlignment="Left" Height="42" Margin="251,94,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="224" Background="##FFD4D4CC" IsEnabled="False" FontSize="16"/>
            <TextBox Name="errortxtbx" HorizontalAlignment="Left" Height="28" Margin="91,168,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="344" FontSize="16" FontFamily="Verdana" Visibility="Hidden" IsEnabled="False" Foreground="Red" BorderBrush="##FFACB4CD" Background="##FFDAB1B1"/>
            <Button Name="CopyBtn" Content="Copy to Clipboard" HorizontalAlignment="Left" Margin="494,90,0,0" VerticalAlignment="Top" Width="140" Height="51" Background="##FFCDDAD5" FontSize="14" Foreground="##FFB63232"/>
        </Grid>
    </Window>
$"
ObjectClrOption('useany', 'System')
ObjectCLrOPtion('useany', 'PresentationFramework')
ObjectCLrOPtion('useany', 'PresentationCore')
ObjectClrOption('useany', 'System.Xml')
oDOc =  ObjectClrNew('System.Xml.XmlDocument')
oDoc.LoadXml(XAML)
oXML = ObjectClrNew('System.Xml.XmlNodeReader',oDoc)
objMReader = ObjectClrNew('System.Windows.Markup.XamlReader')
objWindow = objMReader.Load(oXML)
objWindow = ObjectClrType( 'System.Windows.Window', objWindow )
objWindow.Show()
Timedelay(5) ;just display for 5 seconds: can WB process any further
Stan - formerly stanl [ex-Pundit]

spl

Oh, and as a quick note, the XAML is easily obtained from Visual Studio which gives nice options from the Windows toolbox, check out https://theautomationcode.com/create-gui-with-wpf-in-powershell-part-iv/

Yes, it is powershell, but the XAML code could easily be fit into the WB 'template' I posted, just have to remember for WB multi-line code to replace : with :: and # with ##. The kicker is, of course, having WB execute events like Add-Click()...
Stan - formerly stanl [ex-Pundit]

cssyphus

Thanks Stan. I feel like I am I am missing something. What are some real-world practical applications when these examples could be used? (Not these specific examples, bien sur, but the XAML-to-WB technology...) When would most of us find this useful?

spl

Quote from: cssyphus on September 09, 2024, 12:05:15 PMWhen would most of us find this useful?

Probably not useful, unless you needed to control events, or create dialogs with more advanced controls.
Stan - formerly stanl [ex-Pundit]

spl

I am having fun playing with XAML, especially to build custom messages. Just have to figure out the clicking.
Stan - formerly stanl [ex-Pundit]

spl

This uses System.Windows.Controls.MediaElement which can be instantiated in the CLR.
ObjectClrOption('useany', 'System')
ObjectCLrOPtion('useany', 'PresentationFramework')
ObjectCLrOPtion('useany', 'PresentationCore')
oMedia = ObjectClrNew('System.Windows.Controls.MediaElement')

but would require XAML for a container if playing a video. Maybe possible with compiled C# from the CLR.
Stan - formerly stanl [ex-Pundit]

spl

and a simple XAML grid with button
Stan - formerly stanl [ex-Pundit]

JTaylor