Note before reading: This is a general question, that I chose to ask about a specific extension, but the answer should be the same... I guess.
I've started to implement localization in my project, and I'm using the WPF Localization Extension lib, but I have a few questions:
In order for the lib to work, it's is required to add this definition to every xaml page:
xmlns:lex="http://wpflocalizeextension.codeplex.com"
And I have 2 questions regarding that:
1. What if the URL goes off, for some unknown reason? Will my application just lose all of the extension's functionality? Is there an option to someone avoid using the url, and instead using some local file or something...?
2. I'm using calibrun.micro, and obviously my application has a few pages, and they're all embedded within the ShellView.xaml page through a ContentControl. Is there an option to write the namespace declarations (xmlns:lex, etc... - see code below) in just the shellview and have it affect all of the other pages automatically? It sounds really inefficient to have to specify the declarations in each single xaml page.
Extra Info:
Extension page: http://wpflocalizeextension.codeplex.com/
Namespace declarations/definitions:
xmlns:lex="http://wpflocalizeextension.codeplex.com"
lex:LocalizeDictionary.DesignCulture="en"
lex:ResxLocalizationProvider.DefaultAssembly="WpfApplication3"
lex:ResxLocalizationProvider.DefaultDictionary="Strings"
1 - That url is only symbolic. It doesn't point to an actual internet address. it could be "http://whatever.com" and it would still work as long as it is exactly the same as the xml namespace defined in the XmlnsDefinition in the assembly you're referring to.
To be clear, it's just a name (which just happens to have an internet-like format), not a website address.
2 - No, there's no way to declare a project-wide xmlns. That's one of the loudest complains we have to microsoft, but they abandoned WPF in favor or WinRT so I'm not hoping for a fix.
Related
I have these files.
"Control.cs" [this has method activateabc()] and "abc.xaml" in an assembly (created as a Class Library) and I have referred it in my working project(Windows Phone 8.1 Runtime App). I have added
Frame.Navigate(typeof(abc)) within the activateabc() and when I call activateabc() from the working project it throws XAMLPARSEEXCEPTION.
Any idea how do I navigate to XAML page in another assembly? Also I have no dots or hypens or underscores in any of my assembly names.
Edit: NavigationService.Naivage()is available in Windows Phone 8 to do the job. However, Frame.Navigate() allows navigation to a type rather than to a URI as in WP8. So please tell me a way how to navigate to a XAML page in different assembly in Windows Phone 8.1 Runtime Apps
Can you provide more information please? I don't have an answer but I do have some additional information that might help.
Do you know if it's failing to parse the xaml markup or is it in truth failing to find the abc.xaml file? I bet this is the real problem. If it's failing to find the file you might need to modify the xaml file Uri to include the assembly name. I don't know how to override the default file load location for pages since that code gets generated but the Uri would look like this.
If your assembly is MyCustomControls.dll then the Uri would be new Uri("ms-appx:///MyCustomControls/abc.xaml").
If your xaml file is found but some markup is failing you might try to comment out all the markup until there is no load failure then comment it back in by bits until you isolate which bit of markup seems to be the problem. It might be some namespace resolution issue in the app's xamltypeinfo.g.cs. I doubt this is the issue though since you say you added the assembly as a reference.
I hope some of the above information is useful.
I am writing a program for computer vision in c# that part of project SIFT is needed; I downloaded the MEMO library for SIFT :
http://www.nowozin.net/sebastian/tu-berlin-2006/libsift/
In my project I added the two libraries ****libsift.dll & ICSharpCode.SharpZipLib.dll** ** as references in to my projects.
Now that I want to mention libsift on top of the code " USING libsift" it doesnt recognize it;
even more if I wanna make a instance of such class atuo detect doesn't recognize it.
It is weird because I could see the functions of this library in object browser.
I couldnt use the library that I have already imported as references in my project although I could see the functions in object browser? What could be the problem?
(I have c# .Net VS2010 in windows.)
It looks like they're in the root namespace - not in a namespace called libsift. If that is the case, you don't need a using libsift; directive - just try accessing Keypoint etc directly. Or possibly global::Keypoint. It should be noted that dumping types into the root namespace is frowned upon - it makes it hard to avoid conflicts. But that is the fault of libsift.
The other possibility is that you've changed the "Aliases" property on the reference; that should be "global". You can see this in the property panel when you select an individual reference in the solution explorer - alongside things like "Copy Local", "Specific Version", etc. If it is anything else: change it back to "global", or learn about extern aliases.
Tested locally (the types are in the global namespace):
Please excuse the newbie question - my background is Unix and I am very green when it comes to WPF...
//Context//
I need to design a single page WPF-based UI, using Visual Studio, or Blend.
Additionally, I need this to be portable outside the microsoft generated solution... this is because I need to be able to define the business logic within a different c# environment, that is exposed by software called 'NinjaTrader' (for those who may use it).
I am restricted to .NET 3.5
//Additional info//
Right now, I am trying to get to proof-of-concept as quickly as possible. I have successfully implemented the UI using winforms. by simply designing the form within VS, and then copying the auto-generated designer code into my own abstract class definition (say 'myForm') within NinjaTrader. I then have to inherit myForm into a new class definition within a 'standard' NinjaTrader.Indicator class (this is necessary to be able to instantiate the myForm2 class), and by passing the outer class to the constructor of myForm2, and overriding the methods I need for the business logic, I can display a UI upon 'OnStartUp' of the NinjaTrader.Indicator class, and implement the behaviour that I need.
//My problem//
WPF is proving more difficult so far. I have tried copying the class definitions from 'WPFWindow.xaml.cs', and also what is necessary from 'WPFWindow.g.cs' into a single .cs file (due to limitations within NinjaTrader, I must use a single file for this), and then instantiating this class from another NinjaTrader.Indicator class.
Everything is in the same namespace, though I am repeatedly stumped when it comes to the relative Uri and it seems I get the following message, no matter what I do:
Cannot locate resource 'wpfwindow/wpfwindow.xaml'
Now - I am aware that the relative Uri will not be the same, when running from within a different application, and I have even tried copying the WPFWindow.xaml file to a new folder (within what seems to be the current working directory, and without any spaces) and calculating the relative :
string cpath = Directory.GetCurrentDirectory();
string installPath = #"C:\Program Files (x86)\NinjaTrader 7\bin64\WPFWindow\WPFWindow.xaml";
Uri cwUri = new Uri(#cpath);
Uri instUri = new Uri(#installPath);
string relPath = cwUri.MakeRelativeUri(instUri).ToString();
System.Uri resourceLocater = new System.Uri(relPath, System.UriKind.Relative);
System.Windows.Application.LoadComponent(this, resourceLocater);
However, I am still getting the same error.
I would be extremely grateful if anyone has any advice / suggestions as to how I might try to proceed.
Is there another way that I can load an XAML file (that is external to the current application / project), without using a relative Uri in order to display a single UI window? Any advice on what the bare minimum (less is definitely more reliable in this case) I would need to implement in order to do this and define the business logic, would be extremely helpful...
Thanks in advance for any advice
J
EDIT: (& Reponse to Brian S):
Thanks for the response, and also for the reccomendation on material. It is entirely possible that I have misunderstood the necessary architecture involved with WPF...
Therefore, please let me know it that is the case... My understanding is as follows:
The graphical composition, content, layout, etc is all specified within the XAML file. Behaviour, interaction, event handling etc is specified in the code-behind.
Once the XAML markup has been written, I had made the assumption that, in order to instantiate the window I had designed, all I needed to do was to load / parse it into a tree of objects within - lets say - a class that inherits System.Windows.Window, and is named as the same class as in x:class="myClass", within the XAML file.
Upon re-reading what I wrote previously, I realise that I was not all that clear about the situation. I can use multiple files for the solution, without a problem, the issue arises as follows:
With classes that are partial, across 2 files - lets say file1.cs and file2.cs, class methods will only be recognized within the same file that they are defined (unless I actually instantiate the class - after which I can call it's methods). So - for example - I could not specify InitializeComponent() in file1.cs, and then define a constructor in file2 that refers to InitializeComponent()... I hope that makes sense...
What I can do, which seems to work, is to avoid defining methods outside of the file that I need to reference them in. And thus, avoiding the use of partial classes as far as possible.
I can define a class in one file (say class1.cs), then instantiate it from another file (say class2.cs) no problem, by using:
private class1 mynewclass1 = new class1(args)
I can also use:
'System.Windows.Application.LoadComponent(args);'
Though I seem to be running into issues with the relative addressing, as no matter what I try it does not seem to find the .xaml file..
Is there a way that I can try to load the xaml file without using relative addressing? I have been looking at XamlReader, though I'm not sure it can do what I need....
Thanks again,
J
If I follow, you're trying to treat the WpfWindow.xaml file as a loose resource file located in the same directory. This is not how WPF works - the WpfWindow.xaml file is a partial class with the codebehind. This is possible with XAML Resource Dictionaries, but I don't believe it is possible with the WpfWindow.xaml file because they need to be compiled together.
If you want a single-file solution, it is a lot more work, but everything you do in XAML, you can do through code. So you can create a window, add controls, position them and connect behaviors all through the codebehind. Obviously, this is not the ideal approach, but it sounds like you've got some pretty significant limitations (I'm not familiar with NinjaTrader).
The MSDN Documentation will provide help on the code necessary to manually construct and layout a WPF window, or if you are looking for another resource, Applications = Code + Markup, by Charles Petzold goes through doing anything you need to do with WPF from codebehind.
I am working on an existing windows form application. I only need to make few modification, during those changes i came across a scenario where i need to rename an existing namespace aswell. Now after renaming that namespace my project is not running. Although it compiles fine but breaks at the following line of code
ImageList il = new ImageList();
ImageList = il;
il.Images.Add((Image)new Bitmap(GetType(), "Images.ImageFileName.png"));//when this line is executed a dialog box appears and says that "there is no source code available for current location"
Now since i am new to .net world so i study this problem and figure that it arises due to change in namspace. I also trying renaming the namespace in the Resources.Designer.cs
but it also didn't solve my problem
Thanks All.
I find the solution by myself. The purpose of posting solution here is that may be some one else benefit from it.
Infact its a sort of carelessness from my side because i forget to change the value of Property "Default NameSpace" this property contains the old namespace that's why my resource file alwasy point to old namespace
Right click on Resources.resx, select Properties, find Custom Tool Namespace, set the namespace that you need.
Also, why don't you reference your resources in the typed manner like Resources.ResrouceName.
Here is a quick tutorial how you can setup your resources so you don't have to cast and think about namespaces: http://msdn.microsoft.com/en-us/library/7k989cfy%28v=vs.80%29.aspx
try getting rid of that second line, ImageList = il;. what it's doing is replacing a class with an instance of a class. not good.
I have also came across this issue. I had to rename the namespace of my application. After that the designer was ignoring all resources, although they were appearing after building a solution and running the application.
I found that even though I had renamed the namespace, it wasn't replaced in Application Properties under "Default Namespace" textbox. I have changed the old namespace which was still appearing there with the new namepspace and it worked properly afterwards.
That specific overload of the bitmap constructor combines the namespace of the given type with the string name of the resource and looks for a match in the assembly manifest. So in this case it would be the namespace of your class + ".Images.ImageFileName.png". I'm guessing that does not exist. Change the namespace of the Resources.resx by right clicking on it and selecting properties, do a Rebuild and see if it works now.
When I try using a Name="id" and\or x:name="id" I get a compiler error:
The Type 'MyName' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been built.
When I don't have this specified my control runs just fine. Any suggestions?
Well, first of all the right syntax is x:Name, although Name by itself usually (but not always) works too.
Does the x:Class on your root-level element match the name (and namespace!) of your code-behind file? I know that some versions of Blend and VS didn't insert the default namespace correctly, and of course if you've changed it from the default you'll need to make sure you've changed the other file as well.
I've run into this before and believe it's a compiler bug. I ended up just sticking a named ContentControl in my XAML and sticking the user control in it from the code behind. Hopefully someone can share an actual fix for this.