I built a user control in an user control library and I want to include it into my windows universal app. I remember in the old days you had to add something to app.xaml (something like pack:// this is my xaml).
So my thoughts (or hope) I just include my library and user the control. When I do I get - Parser internal error: Object writer 'xClassNotDerivedFromElement'.
I tried adding it as a msappx reference in the App.Xaml, but I may have the syntax wrong. If I can get this working by literally copying over the code itself into my project (which I do not want to do). Suggestions?
Thanks
EDIT: Added source code
public MainPage()
{
_webControl = new NativeWebView.WebUserControl();
_webControl.Loaded += _webControl_Loaded;
_contentView = new NativeWebView.ContentView(_webControl);
this.InitializeComponent();
root.Children.Add(_webControl);
}
public sealed partial class WebUserControl : UserControl, IWebView
{
public WebUserControl()
{
this.InitializeComponent();
}
}
So, I found out the answer. So to include a library into another project, you have to have some extra crazy files (.xr.xml and .xrc). I manually copied them into a folder, but it seems they can get out of date. I found that if I want to include the library from the build directory, I have to check a box in the build properties page (Generate library layout). This copies the files for me. SOLUTION!
Just add namespace of the library into root tag of the page where you use the control, ex. for ImageButton control in WinRT XAML Toolkit:
<Page
[...]
xmlns:toolkit="using:WinRTXamlToolkit.Controls">
[...]
<toolkit:ImageButton [...] />
[...]
If you still get xClassNotDerivedFromElement, it means there's a problem in the library. (need source to track it)
Related
What I've learnt from the MAUI Tutorial is that the XAML file gets translated into equivalent C# code. This means, if I have a handler (say BtnClick) defined on a button (say x:Name="BtnEx"), somewhere while compilation, it'll get translated to BtnEx.Clicked += BtnClick. However, I also know that it is usually a standard to separate the handler from XAML so that one doesn't accidentally delete it, and define it in the code-behind instead. What I did:
<Button
x:Name="CounterBtn"
Text="Click me"
SemanticProperties.Hint="Counts the number of times you click"
Clicked="OnCounterClicked"
HorizontalOptions="Center" />
Code-behind file:
public MainPage()
{
InitializeComponent();
CounterBtn.Clicked -= OnCounterClicked; // method definition omitted in MRE
}
The resultant code worked as if the handler had not subscribed meaning that -= was below the += in the compiled code-behind. So where exactly will the += lie in the compiler code-behind? Somewhere in the ctor after the initializeComponent call or somewhere else entirely?
It doesn't work the way you are thinking. You won't find "equivalent c#", similar to what you would type if you typed it yourself.
AFAIK, xaml is handled the way it was in WPF: its compiled into a data "blob", which is processed by the Maui runtime.
All that shows up in c# is "mappings", so that c# compiler can connect c# references to xaml declarations.
"InitializeComponent" is in the .g.cs, but it does not reveal the xaml details, just the names of elements visible to c#.
"InitializeComponent" is when the equivalent of += is run; but you can't see that.
This is exactly the reason why you find .g.cs files in your projects obj folder. All of them are generated code files. They are created by the compiler when you build your project. The purpose of this files is to provide a generated implementation for partial classes or XAML-generated classes in your project.
For example, when you create a XAML-based user interface in a WPF, UWP or MAUI application, the XAML compiler generates .g.cs files that contain the generated code for the classes that correspond to the elements in the XAML markup. This generated code includes properties, event handlers, and other code necessary to interact with the user interface elements at runtime. Since the elements classes are defined partial, InitializeComponent() then is used to set everything up in your own implementations file (constructor).
In general, you should not make any changes to the .g.cs files, because any changes will be overwritten the next time you build the project. Instead, you should make changes to the related partial classes or XAML markup files and let the compiler generate the updated .g.cs files.
I'm using DNN 9.2 and searching for a possibility to create an own module that will work like the Atlassian Confluence's Expander Macro where I could add additional content.
In my case I want to add other modules, which will be visible if the parent is expanded and hidden if the parent is collapsed.
I thought about to use a Pane control in my module to place several other modules into it. It is an approach that imitates the Evoq's Grid module functionality, but with the additional possibility to collapse and expand its content, because of no such (expander) module already exists.
I already tried to achieve it by adding a Pane control from DotNetNuke.UI.Skins namespace in Page_Load method and calling pane.ProcessPane(). As I can see in database a added module by moving it into our custom (expander) module is related to our pane which is located in our module.
Actually I have some problems by loading and rendering the page, because the module is located under and not in our custom module like it is referenced in database.
Following is my actual code:
In *.ascx file:
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="View.ascx.cs" Inherits="Prototype.View" %>
<div ID="TestModuleDiv" runat="server"></div>
In *.ascx.cs (code behind file):
using System;
using System.Web.UI.HtmlControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.UI.Skins;
protected void Page_Load(object sender, EventArgs e)
{
var paneName = "MyTestPane" + ModuleContext.ModuleId;
var paneControl = new HtmlGenericControl("div");
paneControl.ID = paneName;
TestModuleDiv.Controls.Add(paneControl);
var paneId = paneControl.ClientID.Replace("dnn_", "");
PortalSettings.ActiveTab.Panes.Add(paneId);
var pane = new Pane(paneId, paneControl);
pane.ProcessPane();
}
Does somebody have some more information how I could achieve my wanted behavior?
The aim is to create an expander module that could contain several other modules, but we are not sure how we could build it in a best practice way.
Edit
Sorry, I missed the fact that I'm searching for an approach with minimized JS magic. Therefore I think it has to happen in code behind.
Furthermore the page must remember which "expander" module was collapsed and which expanded.
You might want to take a look at this open source project:
https://github.com/redtempo/dnnstuff.aggregator
The work already has been done.
Well we have reached an approach that will work like we have expected.
The whole adding/moving modules into the expander module works out of the box and automatically with DNN's own functionality side. We have nothing to implement additionally.
We created an own Panel control that inherits from HtmlContainerControl and has some logic to use the parent skin as container and furthermore the parent module to get the active Tab (page) from it. This will all happen in method OnInit.
Also in OnInit method the OnInitComplete methods is registered. In this method we are moving all (previously added) modules into the pane. Otherwise the expander module added modules will not be placed inside the expander, but under it.
After that we have to register our own pane control in active tab and have to call finally ProcessPane on the pane.
I hope it will help everybody who needs something similar.
I'm very sorry for posting no code, but is an implementation for a customer which I'm not allowed to provide to third persons.
i am in the process of porting some of my Windows Phone Applications to Android using Xamarin Monodroid.
I am pretty new with the Xamarin stuff, just bought a license actually.
So far so good as far as recreating the XAML UI in AXML but i am facing a problem with Custom Controls.
Here is what i mean by custom controls:
In .NET, i created a bunch of controls by creating class that inherit from the 'UserControl' class, i created the logic and set the Content. Then i just create new instance with 'new my_control()', etc...
Some of my controls are not created this way but instead i created the UserControl by defining the XAML, where there is no specific logics but when i need to combine 2 or more controls(for example, a colored square with text beside it, so Rectangle + TextBlock) and again i just need to do 'new my_control()' and add it somewhere in the XAML UI(Grid, ListBox, StackPanel, etc...).
How can i achieve something similar with Monodroid?
Thanks in advance!
You can make your own custom view by inheriting the View class. This allows you to do anything. Then you can reference it in your AXML with:
<your.awesome.namespace.AwesomeViewName
android:id="#+id/awesomeView"
android:layout...
/>
Just make sure your namespace name in the AXML is all lower case, otherwise it won't pick it up.
But if you just need a very simple AXML layout that you are going to use a lot, you can create a new AXML file and use the include tag to put it in there.
There is some more general info on some Layout Tricks for Android which will work for Mono for Android as well here: https://developer.android.com/resources/articles/layout-tricks-merge.html
You can do "custom controls" in Mono for Android too - and once you've written them, then you can include them in your axml files.
I'm afraid I don't have any perfectly simple examples to hand, but there's a complicated example in:
https://github.com/slodge/MvvmCross/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.UI.Droid/Resources/Layout/ChildPage_Twitter.axml
If you declare a class MyControl in MyNamespace and inherit that control from an Android View and you can then setup your custom control - including pulling in attributes from the XML - using a constructor like:
public MyControl(Context context, IAttributeSet attrs) { /* ... */ }
and using XML like:
<mynamespace.MyControl android:layout_height='wrap_content' />
One example of this could be the control from https://github.com/Cheesebaron/MonoDroid.HorizontalPager - which could be used from xml using xml like
<mynamespace.controls.HorizontalPager
android:id="#+id/MyPageHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
Any reason why it won't enter the constructor? Here is my constructor:
protected CropImageView(IntPtr javaReference, JniHandleOwnership transfer)
: base(javaReference, transfer)
{
}
The Init method causes the circular dependency when I inflate the crop_image_view xml
I have tried with public, private but no luck... here is my code: https://github.com/slown1/Xamarin.CircleImageCropper
I am facing a problem: I have taken a dropdownList control and ID is
drpDownCountries in an ASP.NET project. The dropdownlist control is placed on page, in the code behind file of C#, while typing the control name drpDownCountries, this control ID is listed in object member list.
The code-behind code looks like this:
drpDownCountries.Attributes.Add("onBlur", "ErrorHighlight('" + drpDownCountries.ClientID + "','" + lblCountry.ClientID + "');");
But when I compile the project I am getting the following error:
Error: The name 'drpDownCountries' does not exist in the current context
I have checked this thing on different machines too, and the same error is occurring. I do not understand what the reason is or how to fix it.
Right-click on the ASPX (or ascx) file, and select Convert to web application (or something like that). That will force a refresh on the designer file.
I had this same problem and what worked for me was to make a change to the .ascx file in Design view and then save it. This finally forced Visual Studio to regenerate the designer.cs file and include my new control.
I have seen this error occur when there is a copy of the .aspx page in the project folder.
Example:
Error occurs in Test.aspx.
There is a Test-copy.aspx file in the project folder.
Delete, rename with a different extension, or move Test-copy.aspx to a different folder.
Error is resolved.
It's possible there is an error in your aspx/aspx file that is causing the designer file not to be updated correctly. You could confirm this by adding something new (eg. "") and see if you can access that. If not, something is probably broken in the markup that you'll need to fix.
So first check that your ascx document is defined like so
ExampleClass.ascx
<%# Control Language="C#" AutoEventWireup="true" CodeFile="ExampleClass.ascx.cs" Inherits="ExampleClass" %>
ExampleClass.ascx.cs
public partial class ExampleClass : System.Web.UI.UserControl
{
protected void Page_Load(object sender, System.EventArgs e)
{
}
}
In aspx this type of error often occurs when you miss runat="server"
Do not let Intellisense fool you. Sometimes (usually after fixing problems with duplicate class names), you simply need to rebuild the project and the reported errors go away. Reopening the file after the build might be necessary.
You should put some code to get help..
Anyway, the problem could be that drpDownCountries is contained within a Panel control.
The Panel control is a Container control, in that it can hold lots of
controls.
In order to access the controls within that Panel control,
you first need to "help" ASP.Net to find it.
The typical way of doing this is to use the FindControl method look here.
Code sample:
DropDownList myDrop = (DropDownList)this.Panel1.FindControl("drpDownCountries");
if(myDrop != null)
{
..somecode..
}
Recreate the project. Just create a new project and add the elements one by one and hope it won't happen again. If it does, well that's part of the Microsoft experience: recreate another project and so on, until you decide to quit your job and join open-source.
CORRECTION
I'm going to redo the project that I have been working on since the last 3 days using ASP .NET MVC. I should be using an open-source tech for sure, but too bad it's not my decision for this project to not use .NET.
If this is happening after copy/move pages to new location, or project, you may simply check if PageName.ascx.designer.cs is included in project.
There is a bug in visual studio (or maybe reshrper): It includes PageName.ascx and PageName.ascx.cs, but not PageName.ascx.designer.cs, which must be included manually.
The only thing that worked for me was to add a temp controller in the aspx file and saving it.
That generated the designer again, and my controllers are now recognized!
You can then remove the temp controller and save; it won't ruin anything.
I have a problem (obviously the question :)
I have a project-- MyProject... hence the rest of the project uses a default of any classes as namespace "MyProject"... no problem.
In my project, I created a custom user control that has many other controls on it (label, textboxes, etc). So, that class is ALSO within the default namespace of "MyProject". All compiles no problem. Just to confirm scope visibility, on this user control, I made sure that the DESIGNER code and the Code-Behind (My code) are BOTH within the same "MyProject" namespace (they are), AND they are both respectively PUBLIC PARTIAL CLASS MyUserControl.
Now the issue. I create a simple form (also in namespace "MyProject" by default). From the toolbox, the "MyUserControl" exists so I drag it onto MyNewForm. Drag/Drop is fine.
Save all, compile, fail... The Designer is adding an extra "MyProject" reference thus making it appear that the user control is actually located at MyProject.MyProject.MyUserControl .. instead of MyProject.MyUserControl.
As soon as I manually remove the extra "MyProject.", save and compile, all is fine. However, if I re-edit the form, change something, M$ changes it back to the original "MyProject.MyUserControl" reference.
All that being said, here are the snippets from my project...
namespace MyProject
{
partial class MyNewForm
{
...
private void InitializeComponent()
{
// THIS is the line that has the extra "MyProject." reference
// when I manually remove it, all works perfectly
this.MyUserControl1 = new MyProject.MyUserControl();
}
}
private MyUserControl MyUserControl1;
}
Then, in the MyUserControl definition I have...
namespace MyProject
{
public partial class MyUserControl : UserControl
...
}
and from the MyUserControl via the Designer...
namespace MyProject
{
public partial class MyUserControl : UserControl
...
}
Thanks for the help...
What the designer is doing is ok.
--> You have somehere in your project a namespace called MyProject.MyProject.
(Try finding it in "Class View")
PS. to anyone who has same problem but has not found any solution...
Assuming you have created a new WindowsFormApplication;
Create a new WindowsFormApplication project using same name as its solution name.
The default pre-created Form name comes called "Form1". And change its name same as the project name.
Add new UserControl class into the project.
Build/Rebuild the project and check the usercontrol is located at Toolbox.
Drag the usercontrol onto the form and start debugging.
Error: The type name 'userControlName' does not exist in the type 'projectName.FormName'
I had research on net for any solution but couldn't come up with any answer...
But if you change the form name any other different from the project name, it'll be resolved.
If you insist on that the form name and project name has to be same depending on your project needs, a custom DLL could be created and use the usercontrol in it.
Then to use as a control, add the DLL file to "ToolBox" using "Choose Items..."
Finally it is going to be ready to use.
PS2. struggling the same problem for hours, this is the solution I found.
The Namespace Name and Class Name need to be different. The code generated by adding the WCF automatically references the Namespace but if the Class name is the same as the Namespace name, the generated code looks at the Class and nothing will compile.
Name of User Control and Form are same. Using different names will solve the issue.
Since this was a top search result when I had this error, just want to post my cause and solution.
I had two projects within a solution, sharing a 'common' class file which was added as a link.
I added a second 'helper' class file as a link, used its code within the first, and got the error.
The problem was I had not added the second 'helper' class as a link in both projects.
So the other project had an updated 'common' class, but no knowledge of the 'helper' class it now used.
Note to self: pay more attention to the project column of the error list :)
Just encountered this where I had a MasterPage that had an explicit
<%# Import Namespace="MyNamespace" %>
in the .master file
This also happens when you use different pages but with same name. In my case I had created "Grants.xsd" dataset and "Grants.aspx" page. Somehow they got in conflict resulting in this error.
You can easily trouble shoot this by hovering over the culprit keyword (class name) and in Visual Studio 2013, it will tell you exactly where the conflict is.