I have a application previously developed in Visual Studio Express 2010. It uses localized winforms and resx resources used in code.
When the project is opened and compiled using Visual Studio Express 2012 on the same computer the localized strings are not applied, only the default code was found.
The application runs fine and in the winforms designer I can change language to see and edit the localized text of the controls.
I also tried the following code to determine if the languages used were there at runtime, which did report the ones used.
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
foreach (CultureInfo culture in cultures)
{
try
{
ResourceSet rs = resources.GetResourceSet(culture, true, false);
// or ResourceSet rs = rm.GetResourceSet(new CultureInfo(culture.TwoLetterISOLanguageName), true, false);
if (rs == null)
continue;
string isSupported = (rs == null) ? " is not supported" : " is supported";
Console.WriteLine(culture + isSupported);
}
catch (Exception)
{
Console.WriteLine(culture + " is not available on the machine or is an invalid culture identifier.");
}
}
Still when the application is running all I get is the resources for the default language.
I retrieve the resources using:
ResourceManager resources = new ResourceManager(form.GetType());
form.Text = resources.GetString("$this.Text", lang);
where I have verified that lang is correct, but also using
System.Threading.Thread.CurrentThread.CurrentUICulture = lang;
System.Threading.Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(lang.Name);
followed by usage of MyLangResxFile.MyStringResource.
The strings returned are still only the default ones.
Might there be changes or limitations in resx localization support between Visual Studio Express 2010 - 2012?
Update:
I noticed that the localisation works if compiled using msbuild.exe from 3.5 but when using 4.0... the localisations are missing as described above.
sorry for "answering" that question but commenting is not working.
I just want to ask if you could solve that issue in the meantime because I have exactly the same issue.
I even noticed that this issue only happens when target framework < 4.0 is selected. For target framework 4.0 and 4.5 localization is working as before in VS 2010...
Related
In my application I need to get a list of all windows.
var windows = Application.Current.Windows;
If I run my application in debug mode I see not only my forms in the list, but also instances of Microsoft.XamlDiagnostics.WpfTap.WpfVisualTreeService.Adorners.AdornerLayerWindow created by Visual Studio debugging tool for XAML.
What is the right way to filter list of windows to ignore windows created by debugging tool? I don't want to reference additional assembly and check if
window is AdornerLayerWindow
and I don't want to filter like
window.GetType().Name != "AdornerLayerWindow"
Any other ideas?
I just do the trick window.ActualWidth != 0. It works good for me.
Application.Current.Windows
.Cast<Window>()
.Where(w => w.ActualWidth != 0)
.ToList()
.ForEach(w => w.Close());
How can I set the WPF webbrowser controls to render pages in iE10 mode or the higher version installed on a machine?
By default, if I create a .net 4 or .net 4.5 application on any machine of OS > Windows 7, it renders the html pages in IE7 mode only. (Please correct me if I am wrong).
How to enable the application to render the html pages in IE10 mode if IE10 is installed on the target machine?
If you don't want to modify the registry and you control the webpage, you can use the
<meta http-equiv="X-UA-Compatible" content="IE=10">
tag in the document's head. I believe it has to be first or immediately following <title> in order to work.
You can use the registry as described here:
http://msdn.microsoft.com/en-us/library/ie/ee330730%28v=vs.85%29.aspx
EDIT:
for a better explanation you can read this answer too
Will the IE9 WebBrowser Control Support all of IE9's features, including SVG?
For WPF webbrowser control use IE11 mode need , for example, in the constructor of the main window, add the following code:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if(pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
string myProgramName = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().Location);
var currentValue = registrybrowser.GetValue(myProgramName);
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue(myProgramName, 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
If you want to see WPF webbrowser control use IE11 mode in DEBUG mode when run from visual studio, you need to add in the registry all progmam "*". This can be done with the following code:
var pricipal = new System.Security.Principal.WindowsPrincipal(
System.Security.Principal.WindowsIdentity.GetCurrent());
if (pricipal.IsInRole(System.Security.Principal.WindowsBuiltInRole.Administrator)) {
RegistryKey registrybrowser = Registry.LocalMachine.OpenSubKey
(#"Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_BROWSER_EMULATION", true);
var currentValue = registrybrowser.GetValue("*");
if (currentValue == null || (int)currentValue != 0x00002af9)
registrybrowser.SetValue("*", 0x00002af9, RegistryValueKind.DWord);
}
else
this.Title += " ( Первый раз запускать с правами админа )";
Checked for windows 10 and visual studio 2015.
Remark: codes other versions of internet explorer, see here https://msdn.microsoft.com/en-us/library/ee330730(v=vs.85).aspx#browser_emulation
I have a Windows Phone 8 app that I recently upgraded to 8.1 Silverlight. I'd like to use the new tile templates. Right now I have a ScheduledTaskAgent that uses ShellTile.
In order to use the new live tiles I changed the notification service to WNS in my WMAppManifest.xml. I removed the code to register the old background task and added this code instead:
var backgroundAccessStatus = await BackgroundExecutionManager.RequestAccessAsync();
if (backgroundAccessStatus == BackgroundAccessStatus.AllowedMayUseActiveRealTimeConnectivity ||
backgroundAccessStatus == BackgroundAccessStatus.AllowedWithAlwaysOnRealTimeConnectivity)
{
foreach (var task in BackgroundTaskRegistration.AllTasks)
{
if (task.Value.Name == "LiveTileBackgroundTask")
{
task.Value.Unregister(true);
}
}
BackgroundTaskBuilder taskBuilder = new BackgroundTaskBuilder();
taskBuilder.Name = "LiveTileBackgroundTask";
taskBuilder.TaskEntryPoint = "BackgroundTasks.LiveTileBackgroundTask";
taskBuilder.SetTrigger(new TimeTrigger(15, false));
var registration = taskBuilder.Register();
}
I created a Windows Phone 8.1 Windows Runtime Component called BackgroundTasks that contains a BackgroundTask called LiveTileBackgroundTask:
public sealed class LiveTileBackgroundTask : IBackgroundTask
{
public void Run(IBackgroundTaskInstance taskInstance)
{
BackgroundTaskDeferral deferral = taskInstance.GetDeferral();
const string xml = "<tile>"
+ "<visual>"
+ "<binding template='TileWideText01'>"
+ "<text id='1'>Text Field 1 (larger text)</text>"
+ "<text id='2'>Text Field 2</text>"
+ "<text id='3'>Text Field 3</text>"
+ "<text id='4'>Text Field 4</text>"
+ "<text id='5'>Text Field 5</text>"
+ "</binding> "
+ "</visual>"
+"</tile>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
TileNotification tileNotification = new TileNotification(doc);
TileUpdateManager.CreateTileUpdaterForApplication().Update(tileNotification);
deferral.Complete();
}
}
I added a reference to this assembly in my Windows Phone project.
I also added a Background task declaration in my Package.appxmanifest that has BackgroundTasks.LiveTileBackgroundTask as an Entry point. I selected Timer and System event as supported task types.
When I run the app though, nothing happens. No live tile appears. I ran through the background task and everything goes well without any exceptions.
You say "No live tile appears". The code you've posted does not create a live tile - it just updates one. You have to manually pin it - the primary tile cannot be pinned through code.
If that's not the problem, maybe you're not looking at the wide tile? This template is for a wide tile, so the square tile won't be updated by this. I'd suggest using the NotificationsExtensions library. It was originally for Windows Store apps, but I think it would work for WP as well. (I've used it, but just for a test, not for real, so there may be issues.) It allows you to easily specify the template and params for both wide and square tiles.
And finally, to have a wide tile, you have to manually edit the Package.appxmanifest file. You must add the Wide310x150Logo attribute to the DefaultTile element.
That's all I can think of. Hope it helps.
Continuous background execution is not supported for Silverlight 8.1
apps
Windows Phone 8 apps can continue to run in the background after the
user navigates away from the app under certain conditions. This
feature is not available for Silverlight 8.1 apps. If you need this
feature, you should continue to use a Windows Phone 8 app. For more
information, see Running location-tracking apps in the background for
Windows Phone 8.
Platform compatibility and breaking changes for Windows Phone Silverlight 8.1 apps
Windows Phone 8.1 Windows Runtime Component can only be used with Windows Phone 8.1 Runtime(Store) app
How do I use the word editor in a WPF application? Is it possible using windows forms hosting in WPF only? Is there another way to accomplish that?
I found AvalonEdit but it does not have features that I need. So using this way, my problem may not be solved.
Also there is some stuffs out there to host a windows forms control in WPF, but it could not be my answer.
I want to understand that is there a way to use word editor in a native way in a wpf app?
Will all APIs be available in that solution?
Thanks in advance.
You can host MS Word (2007/2010 and probably other versions) from within a WebBrowser control, this works in WinForms and should work in WPF too. A .NET API is provided for automating Word, documented here. The required interop assemblies ship with Office 2010, so deployment is a lot simpler than previous Office versions.
See this Microsoft Support article for more details on hosting Word within a WebBrowser control. The Screenshot below shows Word embedded within a host Winforms application.
Note that this only works reliably for a single hosted instance of Word, so you can't show 2 Word documents side by side in the same application. Also, the Ribbon can sometimes go missing - but Word hasn't ever caused the application to crash.
Administrative rights are required to make the required registry updates as there are potential security issues. One easy method to make the registry updates is to write a script, but the following (revised/untested) code shows how this can be done in c# for Word, Excel and PowerPoint:
using System.Security.AccessControl;
private Dictionary<string,uint> OfficeBrowserRegKeys()
{
string[] officeRegKeyArray = new string[]
{
#"SOFTWARE\Classes\Word.Document.12",
#"SOFTWARE\Classes\Word.DocumentMacroEnabled.12",
#"SOFTWARE\Classes\Excel.Sheet.12",
#"SOFTWARE\Classes\Excel.SheetMacroEnabled.12",
#"SOFTWARE\Classes\Excel.SheetBinaryMacroEnabled.12",
#"SOFTWARE\Classes\PowerPoint.Show.12",
#"SOFTWARE\Classes\PowerPoint.ShowMacroEnabled.12",
#"SOFTWARE\Classes\PowerPoint.SlideShow.12",
#"SOFTWARE\Classes\PowerPoint.SlideShowMacroEnabled.12"
};
Dictionary<string,uint> officeRegKeys = new Dictionary<string, uint>();
uint wrdVal = 0x80000024;
uint excelVal = 0x80000A00;
uint powerPtVal = 0x800000A0;
foreach(string keyName in officeRegKeyArray)
{
if (keyName.Contains("Word"))
{
officeRegKeys.Add(keyName, wrdVal);
}
else if (keyName.Contains("Excel"))
{
officeRegKeys.Add(keyName, excelVal);
}
else
{
officeRegKeys.Add(keyName, powerPtVal);
}
}
return officeRegKeys;
}
private void setNewOfficeKeys()
{
uint editFlag = 0x00010000;
Dictionary<string,uint> officeRegKeys = OfficeBrowserRegKeys();
foreach (KeyValuePair<string, uint> kvp in officeRegKeys)
{
try
{
RegistryKey rKey = Registry.LocalMachine.OpenSubKey(kvp.Key,
RegistryKeyPermissionCheck.ReadWriteSubTree,
System.Security.AccessControl.RegistryRights.SetValue);
rKey.SetValue("BrowserFlags", unchecked((int)kvp.Value),
RegistryValueKind.DWord);
rKey.SetValue("EditFlags", unchecked((int)editFlag),
RegistryValueKind.DWord);
}
catch (Exception e) { string msg = e.Message; }
}
}
Well, Word proper isn't technically designed to be hosted by another app, whether it's WPF, WINFORMS or anything else.
You CAN use api tricks (like SetParent) to move the Main Word window into a WPF hosted window. I've done it before, but it's pretty tricky business and it's very easy to miss things that cause GPFs (both in Word and your app).
Is there any reason why it needs to be "Word in your app"? Why not write a little word addin and then launch Word from your app when necessary. then the Addin can communicate with your app, or your DB or whatever as necessary from within Word.
Users may find that to be a more usable approach in any case.
We are developing a multilingual Winforms application using visual studio 2008. I am trying to figure out how I can create multilingual reports using crystal Reports.
Is there any thing similar to .net resource files in the Crystal reports world?
I'm sorry that I'm robbing you of your tumbleweed badge, but I don't think Crystal has the multiple language support similar to .NET. I think that your only option is to have a separate report for each language and pass the data into the report in the language that you wish to display.
Here is a link of a similar answer.
http://www.dbforums.com/crystal-reports/991737-crystal-report-multillingual-support.html
This would be a manual way of doing this:
Create a report for each language you want and put into the proper folders structure. i.e. all japanese reports will go into rpt_ja/ folder.
Use .Net Resource file to specify report resource name and full resource name for each language:
resource.resx
RPT_SAMPLE -> report01.rpt
RPT_SAMPLE_FULL -> MyCompany.NameSpace.Reports.Report01.rpt
resource.ja.resx
RPT_SAMPLE -> rpt_ja\report01.ja.rpt
RPT_SAMPLE_FULL -> MyCompany.NameSpace.Reports.Report01.ja.rpt
Then use this value in the report code file: Open the report .cs file and change:
public override string ResourceName {
get {
// Change this to HttpContext.GetGlobalResourceObject("Resource", "RPT_SAMPLE").ToString();
return "report01.rpt";
}
set {
// Do nothing
}
}
public override string FullResourceName {
get {
// Change this to HttpContext.GetGlobalResourceObject("Resource", "RPT_SAMPLE_FULL").ToString();
return "rpt_ja\report01.ja.rpt";
}
set {
// Do nothing
}
}
EDIT: HttpContext is for ASP.Net web application. In winform, you can try Properties.Resources.ResourceManager.GetString() to get the string from resources
A client ask me for a solution to this issue. I developed a solution based on Crystal Reports contentLocale keyword and Custom Functions. See my posting: http://www.cogniza.com/blog/?p=55.