如何本地化应用程序,以便它使用特定的区域设置,而不管设备上设置的区域设置是什么?我想让用户可以设置他们选择的语言.
到目前为止,我在我的Application类中有这样的代码:
@Override
public void onCreate()
{
//Set locale
String l = Preferences.getLocale(getApplicationContext());
if (!l.equals(""))
{
Locale locale = new Locale(l);
Locale.setDefault(locale);
Configuration config = getBaseContext().getResources().getConfiguration();
config.locale = locale;
getBaseContext().getResources().updateConfiguration(
config, getBaseContext().getResources().getDisplayMetrics());
}
LogData.InsertMessage(getApplicationContext(), "Application started");
}
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,我似乎在set locale中显示得很好(TextViews)但是菜单标题和toasts将落入默认语言环境.
有没有1-2-3如何让它正常工作?我使用2.2版本
我正在尝试将特定的类注入我的WCF服务,但它不起作用,我无法理解为什么.我对MEF和模式非常陌生,只是想让它发挥作用.看了一系列的视频来了解它是什么,但引导不适用于我的情况,因为它不是Silverlight http://channel9.msdn.com/blogs/mtaulty/mef--silverlight-4-beta-part-1 -介绍
这是我的Web应用程序的Global.asax代码.这是非MVC,只是常规的ASP.NET应用程序:
private void Application_Start(object sender, EventArgs e)
{
RegisterRoutes();
var catalog = new WebScopedCatalog(new DirectoryCatalog(Server.MapPath("~\\bin")));
var container = new CompositionContainer(catalog);
container.ComposeParts(this);
}
Run Code Online (Sandbox Code Playgroud)
首先,我不确定我是否正确引导它..第二,我正在使用http://www.timjroberts.com/2011/02/web-scoped-mef-parts/作为网络范围部件的指导.我需要它,因为一些注入的对象应该只在请求期间生存.
现在,我有以下课程:
[Export(typeof(ITest))]
[WebPartCreationPolicy(WebCreationPolicy.Session)]
public class Test : ITest
{
public string TestMe()
{
return "Hello!";
}
}
Run Code Online (Sandbox Code Playgroud)
我的服务看起来像:
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
public class MobileService
{
[Import]
public ITest MyTestClass { get; set; }
public MobileService()
{
int i = 10;
}
Run Code Online (Sandbox Code Playgroud)
当断点在i = 10时命中 - 我在MyTestClass中有NULL.很明显,MEF没有为我初始化这个课程.我错过了什么吗?
编辑:
当我检查目录时 …
我有自定义控件,我有接口这个控件暴露给它的用户.
public interface ILookupDataProvider
{
string IdColumnName { get; }
IEnumerable<IDataColumn> Metadata { get; set; }
void GetDataAsync(string parameters,
Action<IEnumerable<object>> onSuccess, Action<Exception> onError);
}
Run Code Online (Sandbox Code Playgroud)
所以,这是我尝试公开异步操作 GetDataAsync
但我不知道如何在我的实现接口的类中实现此方法.我理解这部分,因为我有方法将执行然后onCompletion,onSucess或onError委托将被调用.
有人可以帮助解决如何编写这些问题的语法吗?
编辑:
它是4.0,我不能使用await命令
编辑2:
我使用DevForce框架来加载数据,但是为了这个示例 - 让我们做WCF服务.如何在我的接口实现中包装WCF服务调用?
另外,你认为创建这样的接口以呈现异步操作是否可以?例如,你会以不同的方式做事吗?
我试图使单元格粗体或正常,如果 DataGrid 内的项目新/旧,但偶然发现错误..
看起来像我在这里描述的问题:Why can not bind the Visiblity of a DataGridTemplateColumn in Silverlight 4?
我收到以下错误:
“System.Windows.Data.Binding”类型的对象无法转换为“System.Windows.FontWeight”类型。
我的 XAML 看起来像这样:
<sdk:DataGridTextColumn Header="Subject" Binding="{Binding Subject}" CanUserReorder="True" CanUserResize="True" CanUserSort="True" Width="Auto" FontWeight="{Binding IsNew, Converter={StaticResource BoolToFontWeightConverter}}" />
Run Code Online (Sandbox Code Playgroud)
我的问题是有什么解决方法可以使其正常工作吗?我什至没有使用模板列,它是纯文本列..
public class BoolToFontWeightConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return ((bool)value) ? FontWeights.Bold : FontWeights.Normal;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return (FontWeight)value == FontWeights.Bold;
}
}
Run Code Online (Sandbox Code Playgroud) 这是我的XAML:
<Image
VerticalAlignment="Center" HorizontalAlignment="Center"
Source="{Binding Input, Converter={StaticResource ByteArrayToBitmapConverter}}">
<Image.RenderTransform>
<RotateTransform Angle="{Binding RotateAngle}" CenterX="100" CenterY="100"></RotateTransform>
</Image.RenderTransform>
</Image>
Run Code Online (Sandbox Code Playgroud)
我将图像绑定到数据源并使用转换器来获取Bitmap.那部分有效.但是,我想让它旋转,我在我的VM中设置RotateAngle.问题是 - 所有图像都有不同的尺寸,我不知道如何设置CenterX和CenterY.有没有其他方法可以在不计算额外的X和Y的情况下改变方向?
我responseStream在以下功能中收到警告:
private static string GetResponseString(WebResponse response)
{
using (var responseStream = response.GetResponseStream())
{
if (responseStream != null)
{
using (var responseReader = new StreamReader(responseStream))
{
var strResponse = responseReader.ReadToEnd();
return strResponse;
}
}
}
return string.Empty;
}
Run Code Online (Sandbox Code Playgroud)
我从像这样的地方调用这个函数:
var request = (HttpWebRequest)WebRequest.Create(Uri);
request.Headers.Add("Authorization", "GoogleLogin auth=" + this.SecurityToken);
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = 5000;
// build the post string
var postString = new StringBuilder();
postString.AppendFormat("registration_id={0}", recipientId);
postString.AppendFormat("&data.payload={0}", message);
postString.AppendFormat("&collapse_key={0}", collapseKey);
// write the post-string as a …Run Code Online (Sandbox Code Playgroud) 我有这样的功能:
private T DeserializeStream<T>(Stream data) where T : IExtensible
{
try
{
var returnObject = Serializer.Deserialize<T>(data);
return returnObject;
}
catch (Exception ex)
{
this.LoggerService.Log(this.AccountId, ex);
}
return null;
}
Run Code Online (Sandbox Code Playgroud)
一切都很好,除了它抱怨return null;部分
无法将表达式类型'null'转换为'T'类型
如何从这样的函数返回null?
我正在使用根DirectoryCatalog创建合成容器.
var catalog = new DirectoryCatalog(".");
Bootstrapper.CompositionContainer = new CompositionContainer(catalog, true);
Run Code Online (Sandbox Code Playgroud)
我的可执行文件是"Main.exe"2个问题:
我正在编写运行后台线程的单例类。以下是它的启动和维护方式:
private void EnsureBackgroundThread()
{
try
{
if (this.RunnerThread == null)
this.RunnerThread = new Thread(this.BackgroundRunner) { IsBackground = true };
if (this.RunnerThread.ThreadState != ThreadState.Running)
{
Debug.WriteLine("----ApplePushNotificatorService.EnsureBackgroundThread ThreadState: " + this.RunnerThread.ThreadState);
this.RunnerThread.Start();
}
}
catch (Exception ex)
{
this.LoggerService.Log(null, ex);
}
}
Run Code Online (Sandbox Code Playgroud)
我在这个类中调用我的方法,TestClass如下所示:
apns.Send("dev", devices, "Testing...", out badIds);
// Wait 5 seconds to let it send stuff through.
Thread.Sleep(5000);
devices.Clear();
devices.Add("some bad id");
// Now let's call this again, but this time we should get back some bad Ids …Run Code Online (Sandbox Code Playgroud) 关于AndroidHttpClient的信息很少,特别是我找不到任何好的例子.从我读到的 - 我可以使用此客户端,它已预先配置为SSL.我的目标是2.2+,所以它对我很有用.
谢谢!
我自己的答案(见下面的代码).
我的应用程序单例版本.请参阅顶部的注释,详细了解我用于生成所有内容的命令行.始终使用相同的密码以确保其有效.PKS文件密码必须匹配.
import android.net.http.AndroidHttpClient;
import android.app.Application;
import android.util.Log;
import idatt.mobile.android.providers.DBLog;
import org.apache.http.conn.ClientConnectionManager;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import java.io.InputStream;
import java.security.KeyStore;
/*
To generate PKS:
1. Created cert in IIS7 and then exported as pfx. Follow instruction on SelfSSL: http://www.robbagby.com/iis/self-signed-certificates-on-iis-7-the-easy-way-and-the-most-effective-way/
1a. Download tool: http://cid-3c8d41bb553e84f5.skydrive.live.com/browse.aspx/SelfSSL
1b. Run: SelfSSL /N:CN=mydomainname /V:1000 /S:1 /P:8081
I use port 8081 on my server
1c. Export from IIS manager to cert.pfx
2. Run command …Run Code Online (Sandbox Code Playgroud) c# ×8
.net ×3
silverlight ×3
android ×2
mef ×2
xaml ×2
asynchronous ×1
devforce ×1
generics ×1
localization ×1
wcf ×1