I got the following code, is going to be a dynamically generated grid:
string xaml = "<Grid Margin='8 8 0 0' Width='175'>" +
"<Grid.RowDefinitions>" +
"<RowDefinition Height='115'/>" +
"<RowDefinition Height='*'/>" +
"<RowDefinition Height='Auto'/>" +
"</Grid.RowDefinitions>" +
"<Image Source='C:/Users/SaFteiNZz/Curro/yo2.png' Height='115' Width='171' Stretch='Uniform'/>" +
"<Button x:Name='BtnEditAc' Grid.Row='0' Style='{StaticResource MaterialDesignFloatingActionMiniAccentButton}' HorizontalAlignment='Right' VerticalAlignment='Bottom' Margin='0,0,16,-20'>" +
"<materialDesign:PackIcon Kind='AccountSettingsVariant' Width='30' Height='30' Margin='0,0,0,5'/>" +
"</Button>" +
"<StackPanel Grid.Row='1' Margin='8,24,8,8'>" +
"<TextBlock TextWrapping='Wrap' FontWeight='Bold'>Pablo Antonio Hernandez Hernandez</TextBlock>" +
"<TextBlock TextWrapping='Wrap' VerticalAlignment='Center'>46080696N</TextBlock>" +
"</StackPanel>" +
"<Border BorderBrush='White' BorderThickness='1' CornerRadius='0' Grid.Row='0' Grid.RowSpan='3'>" +
"<Border.Effect>" +
"<DropShadowEffect BlurRadius='10' Direction='-90' Color='Black' ShadowDepth='0'/>" +
"</Border.Effect>" +
"</Border>" +
"</Grid>";
UIElement element = (UIElement)XamlReader.Parse(xaml, context);
empDisplay.Children.Add(element);
Like that the code works.
But I want to set a click event to the button (BtnEditAc) which if I do directly in the XAML string procs an error(Couldn't create a click from text BtnEditAc_Click or something like that).
Is there a way to set the click event for that button? or connect to a function somehow?
I'm about to make it using CLR objects coded instead of XamlReader, but first I want to know if there's a solution for this.
Hope you know what I'm doing wrong.