Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support ResourcesDictionary With a Code-Behind #78

Open
ghost1372 opened this issue Feb 25, 2023 · 8 comments
Open

Support ResourcesDictionary With a Code-Behind #78

ghost1372 opened this issue Feb 25, 2023 · 8 comments

Comments

@ghost1372
Copy link

hi, i have a Library and in this library i have a ResourcesDictionary file called ItemTemplate.xaml in this file i have a DataTemplate, for using x:Bind method i have to set an empty Code-Behind for this ResourcesDictionary. when i compile my library with merging this ResourcesDictionary into Generic.xaml file and running an example project, i get some exceptions. is this supported? if not can you please add it?

https://github.com/WinUICommunity/LandingsPage/blob/main/LandingsPage/Themes/ItemTemplates.xaml

https://github.com/WinUICommunity/LandingsPage/blob/main/LandingsPage/Themes/ItemTemplates.xaml.cs

@batzen
Copy link
Owner

batzen commented Feb 26, 2023

The code behind file does not seem to be generated, can't you just add a Generic.xaml.cs that has the required content?

@ghost1372
Copy link
Author

Generic file is generated by your tool, how i can add a code-behind for this?

What do you think about this Idea, if we consider a property for example IsCodeBehind

<XAMLCombineItems Include="Themes\ItemTemplate.xaml">
      <TargetFile>Themes\Generic.xaml</TargetFile>
      <Visible>True</Visible>
      <IsCodeBehind>True</IsCodeBehind>
    </XAMLCombineItems>

Then, instead of the contents of this dictionary being placed inside the generic, We only have one reference to this dictionary

in Generic.xaml-->

<theme:ItemItemplate/>

@batzen
Copy link
Owner

batzen commented Feb 26, 2023

The Generic.xaml is generated by my tool, but it doesn't know or care about any code files.
If you just create a Generic.xaml.cs at the same directory the compiler should just pick it up, as my tool runs before the compiler does.

@ghost1372
Copy link
Author

So how about x:class attribute? Does this attribute added to generic.xaml by tool?

@batzen
Copy link
Owner

batzen commented Feb 26, 2023

All attributes/namespaces are taken over to the generated file.
There might only be one issue with your x:class. If you have multiple source files with x:class, but a different value for each that won't work.

Have you tried just adding a Generic.xaml.cs for your case?

@ghost1372
Copy link
Author

ghost1372 commented Feb 26, 2023

I will test as soon as I get home
But I guess it won't work because the x:class (mynamespace.folder.itemtemplate) in itemtemplate.xaml is connected to itemtemplate.cs codebehind
If i create a generic.cs file how exactly will the x:class be connected to the generic.cs file?
I am confused a little

@batzen
Copy link
Owner

batzen commented Feb 26, 2023

You could try copying your existing file and just rename it to Generic.xaml.cs. That might work. I have to admit that i haven't done any WinUI development so far. So it's just guessing from my WPF experience.

@ghost1372
Copy link
Author

Ok tnx i should test, Do you have any comment about my idea? Adding a property in xamlcombineitem csproj? I think this can be work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants