yuluckyvr
Topic Author
Posts: 3
Joined: 10 May 2023, 03:14

Can we add custom markups?

17 May 2023, 03:49

Is it possible to register a custom markup tag, like below
<CustomMarkUp x:Name="AAAA" content="I am a custom context">
	<Button x:Name="Button" Width="100" Content="Click me" Command="{Binding AutoCommandCall}"/>
</CustomMarkUp >
The intention is to do automatic bindings by scanning the XAML and add data context to all of these CustomMarkUps
this control do not need to have its own display, can be a empty container.
 
User avatar
sfernandez
Site Admin
Posts: 3008
Joined: 22 Dec 2011, 19:20

Re: Can we add custom markups?

17 May 2023, 18:50

Of course, you can extend Decorator (which already provides a Child property) and use it in the xaml with the appropriate namespace:
using Noesis;

namespace MyNamespace
{
  public class CustomMarkup : Decorator { }
}
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:MyNamespace">
  <local:CustomMarkup>
    <Button x:Name="Button" Width="100" Content="Click me" Command="{Binding AutoCommandCall}"/>
  </local:CustomMarkup>
</Grid>
Anyways, you don't need any of this to assign a custom data context to the Button, you can just expose it the current view model:
<Grid
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Button x:Name="Button" Width="100" Content="Click me" DataContenxt="{Binding CustomDataContext}" Command="{Binding AutoCommandCall}"/>
</Grid>
This will resolve the AutoCommandCall against the viewmodel exposed in CustomDataContext property. Could that work for you?

Who is online

Users browsing this forum: Bing [Bot] and 6 guests