我正在寻找一种简单的方法来将我的应用程序本地化为日语以及默认的英语.唯一的要求是我们能够以指定的语言启动它.我们使用的是LocBaml的东西,这些东西很笨重,很复杂,容易出错,并且使我们的构建过程非常困难.
我正在考虑将所有内容移回资源文件(Strings.resx,Strings.ja.resx)并只执行静态绑定,如下所示:
<TextBlock Text="{x:Static resx:MyWindow.MessageText}" />
Run Code Online (Sandbox Code Playgroud)
然后在发布时找出他们想要的语言并切换它从哪个资源中提取字符串:
public static void Main(string[] args)
{
if (args[0] == "-lang")
{
Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(args[i + 1]);
}
App app = new App();
app.InitializeComponent();
app.Run();
}
Run Code Online (Sandbox Code Playgroud)
这很简单,似乎唯一真正的缺点是我们无法在运行时切换,这不是我们想要做的事情.我看过一些像这样的本地化扩展:
http://wpflocalization.codeplex.com/
http://www.wpftutorial.net/LocalizeMarkupExtension.html
它们提供了更清晰的Xaml,并且在设计时看起来更好一些,但除了允许您在运行时更改语言之外,我看不出任何功能差异.我在这里遗漏了什么,或者我们应该选择简单而内置的路线?总和我们只有~100个需要本地化的字符串.我认为这里最简单的路线是最好的,特别是考虑到我们应用程序的相对简单性.
所以我正在使用一个旧的数据模型,我必须在我所处理的范围内工作.
当我执行数据库查询时,模型将数据作为a返回
List<Dictionary<string, object>>
Run Code Online (Sandbox Code Playgroud)
每个字典的位置,键是列名,值是列值.你可以想象,使用它是foreach循环和类型转换的噩梦
我希望定义一些POCO视图模型然后制作一些使用LINQ /反射的东西,以及一个"赋值绑定贴图",从可怕的返回值转到我漂亮的干净POCO.所以我可以使用列名和lambda来定义"maps"到我的POCO上的属性,类似于这个......
var Map; // type???
Map.Add("Id", p => p.Id);
Map.Add("Code", p => p.Code);
Map.Add("Description", p => p.Description);
Map.Add("Active", p => p.Active);
Run Code Online (Sandbox Code Playgroud)
然后像这样转换......
List<Dictionary<string, object>> Results = MyModel.Query(...);
List<ProductViewModel> POCOs = new List<ProductViewModel>();
foreach (var Result in Results) // Foreach row
{
ProductViewModel POCO = new ProductViewModel();
foreach (var i in Result) // Foreach column in this row
{
// This is where I need help.
// i.Key is the string name of my column. …Run Code Online (Sandbox Code Playgroud) 我有一个代码库,我想用于ASP.NET MVC和WPF/MVVM前端.业务对象实现为接口,业务逻辑使用这些接口传递数据.
假设我的接口上有一个实现IEnumerable的属性.是否有可能让这个接口的不同版本使用IEnumerable的不同实现?我想要完成的一个例子:
class Reporting
{
public bool RunReport(IReportParams Params);
}
interface IReportParams
{
IEnumerable<Guid> SelectedItems { get; }
IEnumerable<StatusEnum> SelectedStatuses { get; }
}
class MvcReportParams : IReportParams
{
public List<Guid> SelectedItems { get; set; }
public List<StatusEnum> SelectedStatuses { get; set; }
}
class WpfReportParams : IReportParams
{
public ObservableCollection<Guid> SelectedItems { get; set; }
public ObservableCollection<StatusEnum> SelectedStatuses { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
可以这样做吗?
编辑:我也应该问"怎么样",因为当我尝试这个时,我得到类似的错误:
'MvcReportParams'没有实现接口成员'IReportParams.SelectedStatuses'.'MvcReportParams.SelectedStatuses'无法实现'IReportParams.SelectedStatuses',因为它没有匹配的返回类型'System.Collections.Generic.IEnumerable'
ObservableCollection和List都绝对实现IEnumerable,所以这对我来说似乎没有意义.
最后编辑
好吧,有人发布了答案,但由于某种原因他们删除了它,所以我不能将其标记为解决方案.这是我最终做的事情:
interface IReportParams
{
IEnumerable<Guid> SelectedItems { get; }
IEnumerable<StatusEnum> …Run Code Online (Sandbox Code Playgroud) 我知道视图应该只显示内容,并且在显示信息所需的范围之外不做任何逻辑.
在记住这一点时,最好的方法是处理这种简单的场景:
我可以很容易地在视图中执行以下操作:
@if (Model.Children.Count > 0)
{
<p>
You can't delete this!
</p>
}
else
{
using (Html.BeginForm())
{
<p>
Are you really sure you want to delete this?
</p>
<p>
<input type="submit" value="Confirm" /> |
@Html.ActionLink("Cancel", "Index")
</p>
}
}
Run Code Online (Sandbox Code Playgroud)
是否有令人信服的理由制作TWO视图并让控制器根据有多少孩子返回适当的视图?似乎是简单和关注点分离的权衡.
我正在编写一个视频播放器来播放我们的ASIC捕获的帧.它们采用自定义格式,并且我已经提供了解码ASIC状态的功能.视频可以是640x480到2560x1200(!!!)的任何大小.每个状态周期的输出是16x16像素块,我必须将其放入屏幕上的视频中.
每次需要更新屏幕时,我都会收到以下信息:
主要限制:
今天早上我花了一些时间尝试WriteableBitmap,并将它用作Image的源代码,如下所示:
private WriteableBitmap ImageSource;
public MainWindow()
{
InitializeComponent();
ImageSource = new WriteableBitmap(FrameWidth, FrameHeight, 96, 96, PixelFormats.Bgr32, null);
ImagePanel.Source = ImageSource;
}
private void DrawBox(byte Red, byte Green, byte Blue, int X, int Y)
{
int BoxWidth = 16;
int BoxHeight = 16;
int BytesPerPixel = ImageSource.Format.BitsPerPixel / 8;
byte[] Pixels = new byte[BoxWidth * BoxHeight * BytesPerPixel];
for (int i = 0; i < Pixels.Length; i += 4)
{ …Run Code Online (Sandbox Code Playgroud) 我在MVC控制器中有几个Action,它们通过将blob流传递给FileResult来返回Azure blob.像这样:
public FileResult DownloadReport(string Id)
{
// Look up model
string fileName = messenger.ReportTitle(Id);
// Get a reference to the blob
CloudBlockBlob mainReportBlob = cloudBlobContainer.GetBlockBlobReference(Id);
// Return as a FileResult
using (var reportReader = mainReportBlob.OpenRead())
{
return File(reportReader , "application/pdf", fileName );
}
}
Run Code Online (Sandbox Code Playgroud)
我最近将我的Azure存储库更新到最新版本并开始收到以下异常:
System.NullReferenceException未由用户代码处理
HResult = -2147467261
Message =对象引用未设置为对象的实例.
Source = Microsoft.WindowsAzure.Storage
StackTrace:
at e:\ projects\azure-sdk-for-net\microsoft-azure中的Microsoft.WindowsAzure.Storage.Blob.BlobReadStreamBase.ConsumeBuffer(Byte [] buffer,Int32 offset,Int32 count) -api\Services\Storage\Lib\Common\Blob\BlobReadStreamBase.cs:
e:\ projects\azure中Microsoft.WindowsAzure.Storage.Blob.BlobReadStream.Read(Byte [] buffer,Int32 offset,Int32 count)的第222行-sdk-for-net\microsoft-azure-api\Services\Storage\Lib\DotNetCommon\Blob\BlobReadStream.cs:
System.Web.Mvc.FileStreamResult.WriteFile(HttpResponseBase response)第72行
System.Web.Mvc.Vv上的System.Web.Mvc.FileResult.ExecuteResult(ControllerContext context)
中的System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext,ActionResult actionResult)
处于System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList 1过滤器,Int32 filterIndex,ResultExecutingContext) …
我的ViewModel需要知道View中选择了哪个AccordionItem.所以在ViewModel中我有:
public class ServerListControlViewModel : ObservableObject
{
private int _accordion_index;
public int accordion_index
{
get { return _accordion_index; }
set
{
_accordion_index = value;
RaisePropertyChanged("accordion_index");
}
}
}
Run Code Online (Sandbox Code Playgroud)
在视图中,我有
<toolkitLayout:Accordion SelectedIndex="{Binding accordion_index}">
<toolkitLayout:AccordionItem items go here>
</toolkitLayout:Accordion>
Run Code Online (Sandbox Code Playgroud)
问题?Accordion执行花哨的展开/折叠动画,但是accordion_index的set方法永远不会被调用.此外,我可以在VM的构造函数中设置accordion_index,并且在加载View时将调用get方法,并且将返回我的硬编码值,但Accorion会忽略它,并且始终默认为要扩展的第一个项目.为什么?我是WPF的新手,但相当肯定我已经正确地约束了它.
c# ×4
wpf ×4
mvvm ×2
azure ×1
binding ×1
linq ×1
localization ×1
reflection ×1
resx ×1
toolkit ×1