I added the Windows Phone Toolkit with Nuget into my project.
Now I want to replace the default ListPickerPage with a custom page like this can be achieved for the DatePickerPage. (http://blogs.msdn.com/b/delay/archive/2010/09/21/there-are-lots-of-ways-to-ask-for-a-date-creating-custom-datepicker-timepicker-experiences-is-easy-with-the-windows-phone-toolkit.aspx)
Unfortunately this page does not provide an interface from which I could inherit.
The ListPicker.cs seems to have the reference hard coded:
private ListPickerPage _listPickerPage;
Even though it supports the PickerPageUri property.
I copied the ListPickerPage.xaml and code behind from the Source Repository and provided the path to this page as PickerPageUri.
The Page is opened but contains no content!
I think the reason is this part of code in the ListPicker.cs:
_listPickerPage = e.Content as ListPickerPage;
My class is not a "ListPickerPage" and therefore the reference remains null and no values will be set.
Next step I tried was to inherit from ListPickerPage to get the cast done.
Problem here: the public properties Items and some others have "private set" properties.
At the end, I always ended up with an empty target page.
Google + StackOverflow stated many times that one has to copy the page and simply refer to it via PickerPageUri, but this alone seems not to work.
Has anybody managed to get an own ListPickerPage in his project?
Related
I have a background in C++ and recently I started working in C#.
I have written following pieces of code (in Visual Studio):
var list_Loads = database.GetData<Load>().ToList();
var test_list = list_Loads.Where(o => (o.Name.Substring(0, 3) == "123")).ToList();
When I run the program and I move my mouse over both lists, first I get the count, which is very useful, but when I ask for the entries, this is what I get:
0 : namespace.Load
1 : namespace.Load
2 : namespace.Load
...
Not very useful, as you can imagine :-)
So my question: how can I show the Name attributes of those objects?
I thought: no problem. I have a background in native visualisers, so it should be rather easy to turn this into useful information, but then it comes:
In order to alter the way that those objects are represented, there is the first proposal to add a [DebuggerDisplay] "tag" to the definition of that class in source code.
However, as those classes are part of a framework I'm just referring to, I don't have access to the source code and hence I can't modify this.
Then I found another solution, which comes down to: "Write an entire C# project, debug, test and install it and it might work" (see documentation on "Custom visualisers of data" on the Microsoft website).
I almost choked in my coffee: writing an entire project, just for altering the view of an object??? (While, in C++, you just create a simple .natvis file, mention the classname and some configuration, launch .nvload and that's it.
Does anybody know a simple way to alter the appearance of C# object, without needing to pass through the whole burden of creating an entire C# project?
By the way, when I try to load a natvis file in Visual Studio immediate window, this is what I get:
.nvload "C:\Temp_Folder\test.natvis"
error CS1525: Invalid expression term '.'
What am I doing wrong?
Thanks in advance
OP (my emphasis):
In order to alter the way that those objects are represented, there is the first proposal to add a [DebuggerDisplay] "tag" to the definition of that class in source code.
However, as those classes are part of a framework I'm just referring to, I don't have access to the source code and hence I can't modify this.
Does anybody know a simple way to alter the appearance of C# object, without needing to pass through the whole burden of creating an entire C# project?
If you just want to specify [DebuggerDisplay] on a type, you don't have to have access to the source code. You can make use of [assembly:DebuggerDisplay()] and control how a type appears in the debugger. The only downside is that [assembly:DebuggerDisplay()] naturally only affects the current assembly whose code your mouse is hovering over. If you wish to use the customised display in other assemblies that you own, then you must repeat the [assembly:DebuggerDisplay()] definition.
Here's an easy before-and-after example with DateTime. I picked DateTime because we generally don't have access to the source code and it has some interesting properties:
var items = new List<DateTime>
{
DateTime.Now.AddDays(-2),
DateTime.Now.AddDays(-1),
DateTime.Now
};
...which on my machine defaults to:
Maybe I'm fussy and I just want to see:
Day of the week and
Day of the year
...I can do that via:
using System.Diagnostics;
[assembly: DebuggerDisplay("{DayOfWeek} {DayOfYear}", Target = typeof(DateTime))]
...which results in:
Example:
namespace DebuggerDisplayTests
{
public class DebuggerDisplayTests
{
public DebuggerDisplayTests()
{
var items = new List<DateTime>
{
DateTime.Now.AddDays(-2),
DateTime.Now.AddDays(-1),
DateTime.Now
};
}
}
.
.
.
}
Overrides
[assembly:DebuggerDisplay()] can also be used as a means to override pre-existing [DebuggerDisplay] on a 3-rd party type. Don't like what style they have chosen? Is the type showing far too much information? Change it with [assembly:DebuggerDisplay()].
I have an application and I'm using MEF to compose it. I want to know if it is possible to update the Metadata information of the parts after they were imported.
The reason to do this is the following: I display the imported parts' name and an typeof(int) property in a ListBox, and they are not loaded until the corresponding ListBoxItem is selected (pretty standard). Now I want to update the Metadata info of one part when some event raises, so the displayed info in the ListBox is somethind like "[Part name] ([new number])".
I'm importing the metadata as an Interface that defines it's info, but when I set the int property to be editable (with a set accesor) I receive the following execption at composition time:
"The MetadataView 'myMetadataInterface' is invalid
because property 'myInt' has a property set method."
Is there ANY way to achieve this? Or is the metadata ALWAYS read only once the part is created?
I know this question looks weird, but it doesn't make it any less difficult and therefore interesting ;-)
EDIT (based on Lee's answer, in order to keep people to the core of the question)
I just want to know if it is possible to update a Metadata property after the part is composed, but before it is actually loaded (HasValue == false). Don't worry about filtering or finding the part.
I added a property to the export inteface, which is meant only to be represented in the UI and to be updated, this property has no other function and the parts are not filtered by it.
Thanks
Metadata filtering and DefaultValueAttribute
When you specifiy a metadata view, an implicit filtering will occur to
match only those exports which contain the metadata properties defined
in the view. You can specify on the metadata view that a property is
not required, by using the
System.ComponentModel.DefaultValueAttribute. Below you can see where
we have specified a default value of false on IsSecure. This means if
a part exports IMessageSender, but does not supply IsSecure metadata,
then it will still be matched.
citation
Short Version (EDITED in after question edit).
You shouldn't ever need to update metadata at runtime. If you have some data that should be updated and belongs to a mef part, you need to choose to either have it be updated by recompiling, or store that data in a flexible storage outside of the dll. There's no way to store the change you made in the dll without recompiling, so this is a flawed design.
Previous post.
Altering values on the view would by lying about the components loaded. Sure the metadata is just an interface to an object that returns initialized values; sure you can technically update those values, but that's not the purpose of metadata.
You wouldn't be changing the Name field of an instance of Type. Why not? Because it's metadata. Updating metadata at runtime would imply that the nature of the instance of real data is somehow modified.
This line of code, if possible, wouldn't introduce the Triple type.
typeof(Double).Name = "Triple";
var IGotATriple = new Triple();
If you want to alter values, you need to just make another object with that information and bind to that. Metadata is compiled in. If you change it after a part is loaded, it doesn't change anything in the part's source, so you'd be lying. (unless you're going to have access to the source-code and you change it there and recompile).
Let's look at an example:
[Export(typeof(IPart))]
[ExportMetadata("Part Name","Gearbox")]
[ExportMetadata("Part Number","123")]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class GearBoxPart : Part { public double GearRatio ... }
Now, let's assume that you had a UI that showed available parts and their numbers. Now, the manufacturer changes the part number for whatever reason and you want to update it. If this is possible, you might want to consider storing part number in a manifest or database instead. Alternatively you'd have to recompile every time a part number changes.
Recompile is possible. You have a controller UI that does the above, but instead of updating the metadata, you submit a request to rebuild the part's codefile. The request would be handled by parsing the codefile, replacing the part number, then sending off for a batch recompile and redistribute the new dll. That's a lot of work for nothing IMO.
So, you setup a database. Then you change the object metadata to this.
[ExportMetadata("OurCompanyNamePartNumber","123")]
Then you have a database/manifest/xml that maps your unique permanent static part number that your company devises to the current part number. Modifications in your control UI update the database/manifest/xml.
<PartMap>
<PartMapEntry OurCompanyNamePartNumber="123" ManufacturerPartNumber="456"/>
...
</PartMap>
Then the end-user UI does lookups for the part by manufacturer part number, and the mef code looks in the PartMap to get the mef part number.
I am new to SharePoint developement and have a few startup problems which I hope you will help me with.
I am trying to make a custom field type and I am using WPS builder to create the project. Right now I have the following files which are all compiling just fine :)
SuperLookup3.cs
SuperLookup3Control.cs
SuperLookup3FieldEditor.cs
SuperLookup3FieldEditor.ascx (controltemplate)
fldtypes_SuperLookup3.xml (XML)
I have tried look at this example but I just can't get it to work.
My questions
How is the relationsships between the files?
I can see an override of UpdateFieldValueInItem() which is setting the value to the selected item of a dropdown list. But this method is never called (when debugging). How can this be?
Some general advice would be to post this question to the SharePoint Stack Exchange site (if this answer is unsatisfactory), since there are a lot more SharePoint developers there.
From what I understand of that example, it seems to be quite a complex Custom Field Type to start with (given that it has multiple values). There's a good straightforward and pretty well explained tutorial on MSDN that you might want to try out: Walkthrough: Creating a Custom Field Type
Here's a brief explanation of your files (and the classes they contain):
This is the main class of your field, which derives from the SharePoint field base class (SPField). Your naming seems to indicate you're creating a lookup derivative; if so, you may wish to derived from SPFieldLookup.
This is the class the creates the form control displayed on a list item's New, Edit, and Display forms (but not the List View). It's a go-between for the forms and the item's value for this field.
&
This is the section displayed on the Add/Edit Column page. I would expect 3. to have the ending '.ascx.cs' instead of '.cs', since it is the code-behind for 4.; which may be the cause of your problem. This control sets up your field; associating the class in 1. to the list.
This is the field declaration. It says to SharePoint "Hey, I've created my own field; go look here to find it.", and directs SharePoint to the class in 1., which makes the field available on the Add Column page.
I'm having a problem with mapping controls in a subview back to fields on the owning controller. Specifically, I have mapped outlets for each of my "controls" to File's Owner. Monotouch then generated code for the controller's xib designer.cs file to reference these controls as properties on the controller class. However, when I run my code; I get object is null errors when trying to set properties on the controls. Digging into the issue with the debugger; it appears GetNativeField is returning null when trying to access the outlets by their names from the xib file.
Anyone have any ideas why this would be happening? I've checked the .xib file, and the generated code; the Outlet, Property, and Field names are consistent with one another.
Note that the outlets will only be accessible after the view has been loaded and that happens in LoadView() or by accessing the UIViewController's "View" property (this will load the view implicitly).
Only then the the IB content gets constructed and is available for use.
So if you want to change stuff, you would either manually call LoadView(), or override it in your view, call base.LoadView() and then access the outlets.
I figured out what was causing the issue; it was how I was pushing the controller on the stack:
using(var batteryController = new BatteryController()){
navigationController.PushViewController(batteryController,true);
}
It seems that when dispose is called on the controller, the NIB resource is removed from memory; which was causing the issue.
However, this brings up another question. Aren't you supposed to call dispose on the new controller once it's been pushed onto the stack? In objective C, when you push a controller on the stack; your supposed to call release afterwards. So what am I doing wrong then?
you should add the outlets on the AppDelegate. give this a try also on my blog it's a video of a simple calculator, it's in spanish but if you watch it its very self explanatory you can watch it here http://alexsoto.me/calculadora-monotouch it should help you to get started :) hope this helps Good luck, if i can help you on anything else just let me know
Edit: also you can check this video this one uses subviews also should help you, this one its in english http://www.alexyork.net/blog/post/Selecting-a-contact-from-the-Address-Book-with-MonoTouch.aspx
Currently I'm developing a dashboard for the company that I'm working for. The functionality of this dashboard is not interesting for this problem. This dashboard is build up like:
Asp.net page (with a codebehind ofcourse)
Class where webmethods are defined
Javascript external file (with all the funcitonality of the dashboard, this dashboard works fully clientside)
For the rest I'm working with Visual Studio 2010 Ultimate with a TFS (team foundation server) environment and we make use of the jQuery library and .NET framework 4.0 (C#).
Alright, with that information i hope i can explain my problem. The external javascript file contains three classes. I will name them now ClassMain, ClassSub1, ClassSub2. The classes ClassSub1 and ClassSub2 are derived from ClassMain by doing the following javascript command:
ClassSub1 = new ClassMain();
After this instantiation of the ClassMain other properties and methods of ClassSub1 are loaded. The ClassMain can communicate with the properties and methods of ClassSub1 and ClassSub1 can communicate with ClassMain. So this means that they act like one big class with all kinds of functionality.
I explain this because i think my problem lays here but I'm not sure about it. The classes ClassSub1 and ClassSub2 are getting instantiated in the codebehind of the asp.net page. The following snippet explains it:
StringBuilder javascriptBlockBuilder = new StringBuilder();
javascriptBlockBuilder.AppendFormat("var {0};", this.Id);
javascriptBlockBuilder.AppendFormat("Sys.Application.add_load({0}LoadHandler);", this.Id);
javascriptBlockBuilder.AppendFormat("function {0}LoadHandler() {1}", this.Id, "{");
javascriptBlockBuilder.AppendFormat("{0} = new ClassSub1('{0}');{1}", this.Id, "}");
javascriptBlockBuilder.AppendFormat("var {0};", this.OtherId);
javascriptBlockBuilder.AppendFormat("Sys.Application.add_load({0}LoadHandler);", this.OtherId);
javascriptBlockBuilder.AppendFormat("function {0}LoadHandler() {1}", this.OtherId, "{");
javascriptBlockBuilder.AppendFormat("{0} = new SubClass2('{0}');{1}", this.OtherId, "}");
Page.ClientScript.RegisterStartupScript(this.GetType(), "ClassInitialization", javascriptBlockBuilder.ToString(), true);
In this snippet I create a global variable on the page and assign that class to it. The ClassMain gets the same id as ClassSub1 and ClassSub2 so that they make use of the same variable because like i said a few lines up these classes must act as one class (ClassMain and the ClassSub).
This works also but here comes also the problem. Before executing the above snippet (or after) i have some statements like this:
this.myButton.Attributes.Add("onclick", string.Format("{0}.myJavascriptFunctionality();", this.id));
The functionality gets attached to divisions, buttons, etc.
Ok, now I'm going to render my page and the page loads perfectly, but when I click one of the buttons, divisions, etc. Is it telling me that it requires an object. Somehow my global variables with the ClassSub1 and ClassSub2 are lost and now it can't execute my JavaScript commands.
So my question is, how is it happened that my variables are lost? I hope that my explanation is enough to understand.
It looks like you are calling ClassSub1.myJavascriptFunctionality() in the onclick event of myButton.
ClassSub1 is the function definition / prototype - whatever OOP mechanism you are using. You would have to specify the variable name, not the classname.
like so
this.myButton.Attributes.Add("onclick", String.Format("{0}.myJavascriptFunctionality();", this.Id));
I have found an solution for my problem. The problem occured that my references between the two classes (ClassMain and ClassSub) are referencing to the same variable which results in an error that javascript cannot handle. What did I do to fix this problem?
I have found the answer on this page:
http://www.cristiandarie.ro/asp-ajax/JavaScriptPrototypeInheritance.html
ClassSub1.prototype = ClassMain;
ClassSub1.prototype.constructor = ClassSub1;
And during my construction of the object I did the following call:
ClassMain.call(this, id);
Where 'this' is my current class and I pass an 'id' so that i can reference then to my mainobject.