小编Kja*_*tan的帖子

WPF绑定到Listbox selectedItem

任何人都可以帮助以下 - 一直在玩这个,但不能为我的生活让它工作.

我有一个包含以下属性的视图模型;

public ObservableCollection<Rule> Rules { get; set; }
public Rule SelectedRule { get; set; }
Run Code Online (Sandbox Code Playgroud)

在我的XAML中,我得到了;

<ListBox x:Name="lbRules" ItemsSource="{Binding Path=Rules}" 
         SelectedItem="{Binding Path=SelectedRule, Mode=TwoWay}">
<ListBox.ItemTemplate>
    <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="Name:" />
                <TextBox x:Name="ruleName">
                    <TextBox.Text>
                        <Binding Path="Name" UpdateSourceTrigger="PropertyChanged" />
                    </TextBox.Text>
                </TextBox>
            </StackPanel>
    </DataTemplate>
</ListBox.ItemTemplate>
Run Code Online (Sandbox Code Playgroud)

现在ItemsSource工作正常,我得到一个Rule对象列表,其名称显示在lbRules中.

我遇到的麻烦是将SelectedRule属性绑定到lbRules的SelectedItem.我尝试将textblock的text属性绑定到SelectedRule,但它始终为null.

<TextBlock Text="{Binding Path=SelectedRule.Name}" />
Run Code Online (Sandbox Code Playgroud)

我在输出窗口中看到的错误是:BindingExpression路径错误:找不到'SelectedRule'属性.

任何人都可以帮助我这个绑定 - 我不明白为什么它不应该找到SelectedRule属性.

然后我尝试将textblock的text属性更改为bellow,这有效.麻烦的是我想在我的ViewModel中使用SelectedRule.

<TextBlock Text="{Binding ElementName=lbRules, Path=SelectedItem.Name}" />
Run Code Online (Sandbox Code Playgroud)

非常感谢您的帮助.

wpf binding listbox selecteditem

30
推荐指数
2
解决办法
11万
查看次数

带有来自商店C#.Net CNG的密钥的ECDSA签名文件

我正在尝试使用CNG API和Microsoft证书库中的证书使用ECDSA签署文件.我已阅读了大量文档,并且已接近完成但我仍然挂断了从证书导入私钥.我用RSA完成了同样的事情,但似乎完全不同.这是我到目前为止的代码:

    static void signFile()
    {
        X509Certificate2 myCert = 
             selectCert(StoreName.My, 
                        StoreLocation.CurrentUser, 
                        "Select a Certificate",
                        "Please select a certificate from the list below:");

        Console.Write("Path for file to sign: ");
        string path = Console.ReadLine();
        TextReader file = null;
        try
        {
            file = new StreamReader(path);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
            Console.Write("\nPress any key to return to the main menu: ");
            Console.ReadKey();
        }
        UnicodeEncoding encoding = new UnicodeEncoding();
        byte[] data = encoding.GetBytes(file.ReadToEnd());
        ECDsaCng dsa = new ECDsaCng(
            CngKey.Import(StringToByteArray(myCert.PrivateKey.ToString()),
                          CngKeyBlobFormat.EccPrivateBlob,
                          CngProvider.MicrosoftSoftwareKeyStorageProvider));

        dsa.HashAlgorithm = CngAlgorithm.Sha384; …
Run Code Online (Sandbox Code Playgroud)

.net c# cryptography elliptic-curve cng

23
推荐指数
3
解决办法
9084
查看次数

HTML 5 <audio> - 在特定时间点播放文件

我有一个简单的自动播放片段播放音频文件,但我想知道在JavaScript或作为属性播放该文件在某个时间(例如3:26).

<script type="text/javascript">
    var myAudio=document.getElementById('audio2')
    myAudio.oncanplaythrough=function(){this.play();}
</script>

<audio id="audio2" 
       preload="auto" 
       src="file.mp3" 
       oncanplaythrough="this.play();">
</audio>
Run Code Online (Sandbox Code Playgroud)

任何帮助都会很棒.提前致谢 :)

html javascript audio jquery html5

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

用于Windows x64的ASP.NET核心应用程序(.NET Framework)仅在project.assets.json中出错

我想使用VS 2017简化我的ASP.NET核心Web应用程序(.NET Framework)应用程序中的配置.

我已经知道我的网站将在x64环境下的Windows/IIS和.NET 4.6.2下运行.在此应用程序的预见和未预见的未来,没有机会使用从开发到生产的任何其他环境.

所以,我只需要Debug x64和Release x64模式.(不需要AnyCPU和x86!),所以我继续从项目中删除了所有其他配置.

现在,在编译时,我收到以下错误:

'C:\ Projects\MyProject\My.Website\obj\project.assets.json'没有'.NETFramework,Version = v4.6.2/win7-x64'的目标.

确保已为TargetFramework ='net462'和RuntimeIdentifier ='win7-x64'恢复此项目.MD.Website C:\ Program Files(x86)\ Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets

我在Windows 7上开发,我不知道如何解决这个问题.任何的想法?

c# msbuild project.json asp.net-core visual-studio-2017

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

AddEventHandler使用反射

我有这段代码不起作用:

public CartaoCidadao()
{
    InitializeComponent();

    object o = WebDAV.Classes.SCWatcher.LoadAssembly();
    MethodInfo method = 
        this.GetType().GetMethod("Inserted", 
                                 BindingFlags.NonPublic | BindingFlags.Instance);

    EventInfo eventInfo = o.GetType().GetEvent("CardInserted");
    Type type = eventInfo.EventHandlerType;
    Delegate handler = Delegate.CreateDelegate(type, this , method);

    eventInfo.AddEventHandler(o, handler);
}

void Inserted(string readerName, string cardName)
{
    System.Windows.Forms.MessageBox.Show(readerName);
}
Run Code Online (Sandbox Code Playgroud)

Event CardInserted存在于另一个DLL文件中,对象"o"加载OK.委托处理程序具有效果后的值.我只能解雇这个事件.

.net c# reflection events

20
推荐指数
3
解决办法
3万
查看次数

IDX10500:签名验证失败.无法解析SecurityKeyIdentifier

在尝试验证令牌时,我得到以下异常的原因是什么?

TokenValidationParameters validationParameters = new TokenValidationParameters();

validationParameters.ValidIssuers = new List<string>() { "http://www.company.com" };

validationParameters.IssuerSigningToken = new RsaSecurityToken(
  (System.Security.Cryptography.RSACryptoServiceProvider) Certificate.Get().PublicKey.Key);

SecurityToken securityToken = null;

var claimsPrincipal = 
    (FederatedAuthentication
      .FederationConfiguration
      .IdentityConfiguration
      .SecurityTokenHandlers
      .First() as JwtSecurityTokenHandler)
      .ValidateToken(tokenString, validationParameters, out securityToken);
Run Code Online (Sandbox Code Playgroud)

错误:

IDX10500: Signature validation failed. Unable to resolve SecurityKeyIdentifier: 
          'SecurityKeyIdentifier
    (
      IsReadOnly = False,
      Count = 2,
      Clause[0] = X509ThumbprintKeyIdentifierClause(
                    Hash = 0x6B7ACC520305BFDB4F7252DAEB2177CC091FAAE1),
    Clause[1] = System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause
    )
', 
token: '{"typ":"JWT","alg":"RS256","
Run Code Online (Sandbox Code Playgroud)

.net c# security wcf-security jwt

20
推荐指数
1
解决办法
6994
查看次数

如何在C#中获取会话ID

在C#中获取会话ID的正确方法是什么

String sessionId ;
sessionId = Session.SessionID;
Run Code Online (Sandbox Code Playgroud)

要么

 string sessionId = Request["http_cookie"];
 sessionId = sessionId.Substring(sessionId.Length - 24);
Run Code Online (Sandbox Code Playgroud)

实际上我是C#的新手,只是跳进了我找到第二个代码的项目,谷歌我找到了第一个代码,所以任何人都请告诉我实际使用的代码是什么

c# sessionid

19
推荐指数
1
解决办法
7万
查看次数

将'var'初始化为null

以下变量初始化之间的运行时性能是否有任何差异?

var    x = null as object;
var    x = (object) null;
object x = null;
Run Code Online (Sandbox Code Playgroud)

c# null var

19
推荐指数
2
解决办法
1254
查看次数

有什么方法可以将类库函数转换成exe吗?

有没有办法将我的类库程序更改为.exe或单击一次应用程序?目前我把它作为一个DLL.我能够创建一次点击应用程序但安装后无法正常工作.

c# visual-studio

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

删除所有单引号和短划线字符后的SQL注入

即使在所有"单引号"和"破折号字符"都被删除了用户的输入之后,任何人都可以在SQL注入时显示sql语句的示例吗?

SELECT MyRecord   FROM MyTable   
WHERE MyEmail='susan@site.com' AND MyPassword='foo'
Run Code Online (Sandbox Code Playgroud)

(此处不涉及INT.)

每个人似乎都说"是的,我能做到"......但当他们被迫举一个例子时......没有一个人能够表现出来.

(您可以使用任何sql引擎的任何版本,无论是新版本还是旧版本:SQL Server,MySql,SqlLite,PostgreSQL,Oracle以及其他无数版本.)

sql database database-design sql-injection

14
推荐指数
2
解决办法
9061
查看次数