小编Pat*_*zer的帖子

我可以在ASP.Net项目的代码隐藏中使用JSON.Stringify

在ASP.NET项目(MVP模式)的代码隐藏中,我在其中一个演示者中获得了一个字符串,其中包含一些看起来像JSON文件内容的字符串.

然后我用该字符串设置视图的一个属性 - 分配给演示者.

在视图中,字符串显示在TextBox中,但它看起来不太好,因为它不是使用换行符和换行符构造的.我知道有一个名为Stringify的JSON函数可以使这些字符串变得漂亮.

我可以在代码隐藏中调用JSON函数吗?每个例子我在演示者中设置视图的属性?

所以我在演示者中设置它:

this.view.ContentAsJson = GetContentAsJson(uuid);
Run Code Online (Sandbox Code Playgroud)

这是我想做的,如果可能的话:

this.view.ContentAsJson = JSON.Stringify(GetContentAsJson(uuid));
Run Code Online (Sandbox Code Playgroud)

GetContentAsJson 是一个创建并返回JSON字符串的函数.

这是我的看法:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ContentJsonView.ascx.cs" Inherits="WebCenter.PP.PI.WebGui.View.FolderView.ContentJsonView" %>
<%@ Import Namespace="WebCenter.PP.Common.Domain" %>
<div id="DivContentJson" class="clearfix">
    <p>
        <asp:TextBox runat="server" ID="TbContentJson" TextMode="MultiLine" Height="100%" Width="100%" />
    </p>
</div>
Run Code Online (Sandbox Code Playgroud)

这是视图中获取字符串的属性:

public string ContentAsJson
{
   set
   {
       if (!string.IsNullOrEmpty(value))
       {
            TbContentJson.Text = value;
       }
       else
       {
            TbContentJson.Text = "";
       }
   }
}
Run Code Online (Sandbox Code Playgroud)

c# asp.net json

13
推荐指数
2
解决办法
4万
查看次数

更改文化/语言后如何刷新 WPF 窗口和控件

我正在使用 VS 2015 开发一个新项目的 WPF 测试应用程序,用户可以在该项目中在运行时更改语言。

所以我根据这篇文章做了我的测试项目。

我在 Proerties 文件夹中添加了三个 RESX 文件。

在此处输入图片说明

然后我添加了一个构造函数和用于在语言之间切换的方法。

namespace MultipleLanguages
{
    /// <summary>
    /// Interaktionslogik für "App.xaml"
    /// </summary>
    public partial class App : Application
    {
        /// <summary>
        /// The constructor.
        /// </summary>
        public App()
        {
            // Sets the desired language.
            ChangeLanguage("de-DE");
        }

        /// <summary>
        /// Switches to language german.
        /// </summary>
        public void SwitchToLanguageGerman()
        {
            ChangeLanguage("de-DE");
        }

        /// <summary>
        /// Switches to language english.
        /// </summary>
        public void SwitchToLanguageEnglish()
        {
            ChangeLanguage("en-US");
        } …
Run Code Online (Sandbox Code Playgroud)

.net c# wpf xaml

6
推荐指数
1
解决办法
5229
查看次数

通过WiX-Bundle安装后如何激活IIS功能?

我已经制作了带有某些先决条件的WiX-Bootstrapper捆绑包,例如IIS Express 8.0。在虚拟机上,IIS的安装正常。在下一步中,我想激活某些IIS功能。所以我在MSI项目的Product.wxs中尝试了以下几行:

<Product>
    [...]
    <Property Id="INSTALLIISPROP"
              Value="C:\Windows\System32\dism.exe"></Property>
    <CustomAction Id="InstallIISCA"
                  Return="check"
                  Property="INSTALLIISPROP"
                  Execute="deferred"
                  HideTarget="yes"
                  Impersonate="yes"
                  ExeCommand="/Online /Enable-Feature /FeatureName:IIS-WebServerRole /FeatureName:IIS-WebServer /FeatureName:IIS-CommonHttpFeatures /FeatureName:IIS-StaticContent /FeatureName:IIS-DefaultDocument /FeatureName:IIS-RequestFiltering /FeatureName:IIS-IPSecurity [...]></CustomAction>
    <InstallExecuteSequence>
        <Custom Action="InstallIISCA"
                Before="InstallFinalize">
            <![CDATA[NOT Installed AND IISMAJORVERSION]]>
        </Custom>
    </InstallExecuteSequence>
</Product>
Run Code Online (Sandbox Code Playgroud)

但这无济于事。没有IIS功能被激活。我做错了什么?

最后,这里是用于IIS安装的WXS文件:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
    <Fragment>
        <util:RegistrySearch Root="HKLM"
                             Key="SOFTWARE\Microsoft\InetStp\Components"
                             Value="Install"
                             Variable="IisExpressX64"
                             Win64="yes"/>
        <util:RegistrySearch Root="HKLM"
                             Key="SOFTWARE\Microsoft\InetStp\Components"
                             Value="Install"
                             Variable="IisExpressX86"/>

        <PackageGroup Id="IisExpress_8_0">
            <MsiPackage Id="IisExpress8_0_X64"
                        Cache="yes"
                        Compressed="yes"
                        Permanent="yes"
                        Vital="yes"
                        SuppressSignatureVerification="yes"
                        SourceFile=".\Prerequisites\iis\iisexpress_8_0_RTM_x64_de-DE.msi"
                        InstallCondition="NOT IisExpressX86 AND VersionNT64"/>

            <MsiPackage Id="IisExpress8_0_X86"
                        Cache="yes"
                        Compressed="yes"
                        Permanent="yes"
                        Vital="yes"
                        SuppressSignatureVerification="yes"
                        SourceFile=".\Prerequisites\iis\iisexpress_8_0_RTM_x86_de-DE.msi"
                        InstallCondition="NOT IisExpressX86 …
Run Code Online (Sandbox Code Playgroud)

iis wix

3
推荐指数
1
解决办法
1804
查看次数

在WPF中将父高同步到子高

我正在使用VS 2015和WPF开发遮罩设计器,可以在其中拖动,移动控件和调整控件的大小。这些控件之一是具有TextBlock作为内容的Label。

在我的XAMl中看起来像这样:

<Label Background="AliceBlue" HorizontalAlignment="Left" Margin="10,5,0,0" VerticalAlignment="Top">
    <TextBlock TextWrapping="Wrap" Height="Auto">Label</TextBlock>
</Label>
Run Code Online (Sandbox Code Playgroud)

对于TextBlock,我已将TextWrapping设置为“ Wrap”,将Height设置为“ Auto”。当我尝试将Label的高度调整为允许的最小值时,TextBlock的内容仍将完全可见。我用TextBlock尝试了一下,它起作用了。但是,当我尝试使用实现TextBlock的Label进行尝试时,它不起作用,TextBlock的内容不再完全可见。

如何将父母的身高与孩子的身高同步?

提前致谢!帕特里克

wpf xaml

3
推荐指数
2
解决办法
3625
查看次数

在WPF DataGrid中输入时用逗号替换逗号

我有一个带有DataGrid的WPF应用程序,它绑定到ObservableCollection.集合类型是一个类,它包含一个或多个类型为double的属性,用于十进制值.在XAML中,我已经定义了DataGrid-Columns:

<DataGrid.Columns>
    <DataGridTextColumn x:Name="col_LowerBound"
                        Binding="{Binding LowerBound, NotifyOnTargetUpdated=True, Mode=TwoWay, UpdateSourceTrigger=LostFocus}"
                        Header="Lower bound"/>
</DataGrid.Columns>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,我正在使用UpdateSourceTrigger LostFocus而不是PropertyChanged.在PropertyChanged的情况下,输入会立即被检查,并且会出现像"."这样的字符.会导致不可信.通过使用LostFocus,我可以用点输入小数.

现在我想输入逗号并用点替换它.我可以在KeyDown-或PreviewKeyDown事件中进行替换以及如何进行替换?我不知道如何更换值,而KeyDown和TextBox的类似情况没有太大帮助.

c# wpf xaml datagrid

2
推荐指数
1
解决办法
1335
查看次数

如何从C#中的资源字典(XAML)中获取值

我正在开发一个WPF应用程序,用户可以在运行时更改语言(而不是当前的文化!).所以我有多个XAML类型的资源字典,我添加了文本,使我的WPF-app多语言像这样:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:system="clr-namespace:System;assembly=mscorlib"
                    xmlns:local="clr-namespace:Validation_DataAnnotations2.Resources">
    <system:String x:Key="firstname">First name</system:String>
    <system:String x:Key="lastname">Last name</system:String>
    <system:String x:Key="mainwindowtitle">Validation with DataAnnotations</system:String>
    <system:String x:Key="german_language">German</system:String>
    <system:String x:Key="english_language">English</system:String>
    <system:String x:Key="insert_first_name">The first name has to be inserted</system:String>
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

WPF窗口和控件受窗口资源的约束.但我正在使用DataAnnotations进行验证.我的第一个想法是在我的viewmodel中验证时将文本提供给键"insert_first_name".所以我试图通过使用它来获得它:

System.Windows.Application.Current.Resources.FindName("insert_first_name")
Run Code Online (Sandbox Code Playgroud)

但是当我使用FindName方法时,我得到null.

当我尝试

System.Windows.Application.Current.Resources.Contains("insert_first_name")
Run Code Online (Sandbox Code Playgroud)

我得到"真实",这意味着密钥存在.

我怎样才能获得钥匙的价值?

protected void ValidateModel()
{
    validationErrors.Clear();
    ICollection<ValidationResult> validationResults = new List<ValidationResult>();
    ValidationContext validationContext = new ValidationContext(personmodel, null, null);
    if (!Validator.TryValidateObject(personmodel, validationContext, validationResults, true))
    {
        foreach (ValidationResult validationResult in validationResults)
        {
            string property = validationResult.MemberNames.ElementAt(0);
            if (validationErrors.ContainsKey(property))
            {
                validationErrors[property].Add(validationResult.ErrorMessage);
            }
            else
            {
                validationErrors.Add(property, new List<string> { …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml dictionary

2
推荐指数
1
解决办法
4814
查看次数

标签 统计

c# ×4

wpf ×4

xaml ×4

.net ×1

asp.net ×1

datagrid ×1

dictionary ×1

iis ×1

json ×1

wix ×1