can't access user control public properties - function

I am using VS2008 with both VB.NET and C#
I have created a simple custom user control and have added some public functions to it
my problem is that if I don't drag and drop the user control from the toolbox onto a winform but instead I try to create one dynamically via code - I am not able to access the public functions and properties
I can't understand why there would be a difference but htere seems to be.
would appreciate any help on the matter
thanks

You are defining your variable as type UserControl. As such, intellisense is only going to show you the members of the UserControl class, even if it is in fact of type myCustomControl.
Change your initial declaration to myCustomControl myUC; and you should be good to go.

You neeed to type cast to the usercontrol type
then it works
For Ex :
public partial class uctls_contact_uctlCompanyViewContacts : System.Web.UI.UserControl
{
public bool ReadOnlyMode
{
get;
set;
}
}
UserControl uctlCompanyViewContacts = (UserControl)Page.LoadControl("uctlCompanyViewContacts.ascx");
uctlCompanyViewContacts.ID = "uctlCompanyViewContacts";
panelCompanyViewContacts.Controls.Add(uctlCompanyViewContacts);
((uctls_contact_uctlCompanyViewContacts)uctlCompanyViewContacts).ReadOnlyMode = true;

Are you using the LoadControl method to load the control?
ie.
MyControl ctrl = (MyControl)LoadControl("~/MyControl.ascx");

Related

How to override the Render method?

I'm looking at a control that must output raw HTML and provide rich design-time support.
How to create a custom server control, extend the WebControl class and override the Render method?
Can you provide an example?
regards,
Blanco
This will create a control that extends web control and overrides the Render method (though doesn't actually do anything with it.
public class TestControl : System.Web.UI.WebControls.WebControl
{
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
base.Render(writer);
}
}
As you can see this is a fairly trivial answer but complete so I suspect that you didn't actually ask the question that you intended to.

WindowsPhone CreateBindingSet testing

I am now moving from my code behind xaml dp binding to using CreateBindingSet, as I believe it will be easier to maintain on long run. Previously to confirm that I haven't missed any binding, I had a Windows Phone Test project with a generic test routine - that would parse a view for all the controls, and confirm that each has a correct binding. I did this using
element.GetBindingExpression(dependencyProperty) // from System.Windows
and that's worked beautifully - validating all my views.
But now as I am changing over, all these tests are failing. Has anyone any suggestions on how I can test same thing with when the binding is applied using CreateBindingSet and .Apply.
Thanks in advance.
Rana
Reasoning behind the Madness
Being a lazy sod, I dream of a day where my View would be shared across all platforms; until then, the following would do (I have most in place and working)
BoilerPlate class that would be shared between all platforms:
#if __IOS
... needed namespaces
#else ....
public partial class FirstView
{
private new FirstViewModel ViewModel
{
get { return (FirstViewModel)base.ViewModel; }
}
private void CommonBinding()
{
var set = this.CreateBindingSet<FirstView, FirstViewModel>();
// do common bindings
set.Bind(PageText).For(c => c.Text).To(vm => vm.PageText).OneTime();
set.Apply();
}
}
Then View in Touch would be:
public partial class FirstView : MvxViewController
{
public override void LoadView()
{
// create
}
public override ViewDidLoad()
{
CommonBinding();
}
}
In theory, Views in other platform would be almost similar; just different inheritance (MvxActivity with OnCreate, and OnViewModelSet)/(MvxPhonePage with xaml/alternative, and Loaded Event for binding).
Finally, a common testing way to ensure that all the items has binding set somehow. In my mind, until autoview is supported in wp8, it's just the way to have as much shared code as possible.
I have just started on droid, and trying to make the layout compatible with xibFree, which I have already used in my touch project. If this works, I can then have shared layout between droid and touch (perhaps I should be looking at autoView anyway)
I'm personally not sure what value these tests add that much value to your application - these feel like they are operating at a level of "duplicating code" rather than actually testing any functionality.
However, this is very much down to personal opinion, and if you do want this level of testing, then I think you could do this by:
Inherit a class from https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/WindowsBinding/MvxWindowsBindingCreator.cs
Override ApplyBinding so that you can capture at test time the calls made for each element
Register this class with ioc as the IMvxBindingCreator in your test harness
Use the captured lists of binding requests in your tests

Control view Stack in MvvmCross

How I handle the view stack?
I use MvvmCross and I don't look up the way to do this.
I have a project, I add a custom SplashScreen that I want remove of view Stack.
Thanks in advance.
I don't think there is a direct method to do that for you.
I believe the best way to do this is to create your own custom view presenter and then from within that depending on which platform you are on you can customise your stack of views. For example in iOS you can manipulate MasterNavigationController in a way similar to the answer here.
To find out how to do the custom presenter you can watch N=24 and N=25 in MvvmCross N+1 videos
A general template for an iOS custom view presenter looks like this:
public class CustomPresenter : MvxTouchViewPresenter
{
public CustomPresenter(UIApplicationDelegate applicationDelegate, UIWindow window)
: base(applicationDelegate, window)
{
}
public override void Close(IMvxViewModel toClose)
{
//your custom code on what to happen when a view model is closing
base.Close(toClose);
}
public override void Show(Cirrious.MvvmCross.Touch.Views.IMvxTouchView view)
{
//your custom code on what to happen when a view model needs to be shown
base.Show(view);
}
}

Navigation to other page using User Control

How can we navigate to other page on click on button in user control in windows store app? I tried by making a new frame object and calling navigate method, but no luck till yet.
thanks.
The Frame is a ContentControl that hosts the pages. If you want to navigate back and forth between pages you need to use a single Frame control. The default one is created in the App class in the default Visual Studio templates. You can save the instance reference of that Frame like by having a static property on the App class like: public static Frame RootFrame { get; private set; } and then set it where it is constructed - App.RootFrame = new Frame(). Then you can navigate simply by calling App.RootFrame.Navigate().

1119:Access of possibly undefined property Click through a reference with static type Class

I am making an edutainment game using flash cs5, I'm really new at using flash, in fact we never yet tackle it at school, but I insist on learning about it.
In my codes, I encountered this error
C:\Users\acer\Desktop\JikanLibrary\Main.as, Line 16 1119: Access of possibly undefined property Click through a reference with static type Class.
This is the code I used in my program
package
{
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class Main extends MovieClip
{
var startPage:StartPage;
var jikanBookshelf:JikanBookshelf;
public function Main()
{
startPage = new StartPage;
jikanBookshelf = new JikanBookshelf;
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
addChild(startPage);
function onJikanBookshelf(event:MouseEvent):void
{
addChild(jikanBookshelf);
removeChild(startPage);
}
}
}
}
The error is in this line
startPage.jikanBookshelf.addEventListener(MouseEvent.Click, onJikanBookshelf);
Since I'm really new at flash, I really don't know what went wrong with my codes, it was working a while ago before I put the mouse event. I hope someone could help me.
ActionScript is a case sensitive language. This means that Click is not the same as CLICK. So what you need here is MouseEvent.CLICK
"Why is CLICK all uppercase? Most property names aren't.", you might ask.
That's because CLICK is a static constant property of MouseEvent and the convention amongst ActionScript (and many other languages) programmers is that static constants are written in all uppercase to distinguish them visually from other variables.
'static' means it's a property of the MouseEvent class, not of an instance of MouseEvent.
'const' means it's not a variable: you can't change it's value.
It's a name conflict problem: The class definition name is same as the object name.
The problem in your script is that you have a class definition name startPage and you are trying to create an object of same name startPage.
You have to change the object name to something different. Let say startpage1.