Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
XAML parsing help requested
#2
The grid XAML is invalid.

------------------

Copy XAML from VS and remove the x:Class attribute.

If loaded XAML of entire Window or UserControl, you will not have control variables. And cannot set events in XAML.

Examples.

Code:
Copy      Help
// script ""
using System.Windows;
using System.Windows.Controls;

var xaml = """
<Window 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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfUserControlLibrary1"
        mc:Ignorable="d"
        Title="Window1" Height="450" Width="800">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Height="24" Margin="23,24,0,0" VerticalAlignment="Top" Width="64"/>
        <TextBox HorizontalAlignment="Left" Height="25" Margin="23,67,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="87"/>

    </Grid>
</Window>
"""
;
var w = System.Windows.Markup.XamlReader.Parse(xaml) as Window;
w.ShowDialog();

Code:
Copy      Help
// script ""
using System.Windows;
using System.Windows.Controls;

var xaml = """
<UserControl 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:local="clr-namespace:WpfUserControlLibrary1"
             mc:Ignorable="d"
             d:DesignHeight="450" d:DesignWidth="800">
    <Grid>
        <Button Content="Button" HorizontalAlignment="Left" Height="24" Margin="28,33,0,0" VerticalAlignment="Top" Width="57"/>
        <TextBox HorizontalAlignment="Left" Height="21" Margin="28,75,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="102"/>

    </Grid>
</UserControl>
"""
;
var uc = System.Windows.Markup.XamlReader.Parse(xaml) as UserControl;

var b = new wpfBuilder("Window");
b.R.Add(uc);
b.R.AddOkCancel();
b.End();
b.ShowDialog();


Messages In This Thread
XAML parsing help requested - by burque505 - 08-11-2023, 03:47 PM
RE: XAML parsing help requested - by Gintaras - 08-11-2023, 05:51 PM
RE: XAML parsing help requested - by burque505 - 08-11-2023, 07:05 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)