Enable View and View Model in same file #15200
Replies: 5 comments 3 replies
-
not possible in XAML however one can do that in pure C# as you can also easily bind from code behind. For example: https://github.com/AvaloniaUI/Avalonia.Markup.Declarative |
Beta Was this translation helpful? Give feedback.
-
I am not sure why you would want this when there is already a code behind file that can be used for this if you really want to do it. |
Beta Was this translation helpful? Give feedback.
-
I suspect it would require a lot of IDE work to get the C# tooling to work within a XAML context for autocompletion. |
Beta Was this translation helpful? Give feedback.
-
Yes CDATA ... should be the correct syntax actually. I guess you can do some trickery in the .csproj file - if you use the pre-build phase you can modify your code and files Before the actual build:
You could use .csproj's-capabilities, and run code in the pre-build-phase Before the actual build..: ** ** In fact there are several different ways to invoke code to modify your repository (generated): Other OptionsPre-build Events: Visual Studio and MSBuild allow you to specify pre-build events in your project properties. These are essentially command line instructions that run before your project is built. Pre-build events can call batch files, execute PowerShell scripts, or run any executable with command line arguments.Source Generators in C# 9 and above: Starting with C# 9, Source Generators allow you to generate additional C# source files automatically as part of the compilation process. This is a powerful feature for metaprogramming where code can generate other code. T4 Templates: T4 (Text Template Transformation Toolkit) templates are a part of Visual Studio and can be used to generate C# code, configuration files, or any other type of text file. T4 templates can be set to transform on each build automatically, providing a powerful way to produce source code or other files dynamically before the build process. Roslyn Analyzers: While primarily used for code analysis and providing real-time feedback in the IDE, Roslyn analyzers can also be used to perform code modifications or injections before the build, though this is a more advanced and less common use case. Custom Build Tools: For scenarios where built-in mechanisms aren't sufficient, you can develop custom tools or scripts in the language of your choice (Python, Ruby, Bash, etc.) and invoke them during the pre-build phase using any of the aforementioned mechanisms. This could include anything from code linters to more complex code transformation tools. |
Beta Was this translation helpful? Give feedback.
-
I see. However... it mixes 2 new "technologies" that have different resolution-targets.(axaml is similiar to Wpf's xaml. We should maybe do both, checking the Xaml-AUTOcomplete official/legacy material and the current code/behavior in avaloniaOn 5 Apr 2024 04:23, thevortexcloud ***@***.***> wrote:
The closest thing I know of is the Razor syntax which is fairly special. It lets you more or less seamlessly mix C# and HTML at the same time. EG this is valid Razor:
@{ var i = 0; }
@while (i < people.Length)
{
var person = people[i];
<p>Name: @person.Name</p>
<p>Age: @person.Age</p>
i++;
}
Which will output all the paragraph tags to the page based on how many people are in the people list.
https://learn.microsoft.com/en-us/aspnet/core/mvc/views/razor?view=aspnetcore-8.0
So there is precedent for this sort of thing, but it's fairly complicated. IIRC Microsoft themselves have talked about how complicated it was to add support for Visual Studio.
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Often ViewModels are small and only build for one View, in these cases it would be nice to be able to have view and View Model in the same file.
Example
Beta Was this translation helpful? Give feedback.
All reactions