小编Ahm*_*mad的帖子

从代码设置应用程序资源

我有一个作为WPF应用程序的ac #project,但我现在想把它构建为一个dll.我以前通过从项目中删除app.xaml并将其构建类型设置为dll来完成此操作.

我现在的问题是app.xaml包含一些xaml来实例化应用程序变量.为了解决这个问题,我试图以编程方式在将要调用的第一个xaml窗口中设置这些应用程序变量.

我试图在代码中模拟的xaml是:

<Application.Resources>
    <ResourceDictionary>
      <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Resources/Styles/Shared.xaml"/>
        <ResourceDictionary Source="Resources/Styles/ToolBar.xaml"/>
        <ResourceDictionary Source="Resources/Styles/GroupBox.xaml"/>
        <ResourceDictionary Source="Resources/Styles/ZoomBox.xaml"/>
        <ResourceDictionary Source="Resources/Styles/ScrollBar.xaml"/>
        <ResourceDictionary Source="Resources/Styles/Expander.xaml"/>
        <ResourceDictionary Source="Resources/ApplicationToolbar.xaml"/>
        <ResourceDictionary Source="Resources/DesignerItem.xaml"/>
        <ResourceDictionary Source="Resources/Styles/ToolboxItem.xaml"/>
        <ResourceDictionary Source="Resources/Styles/Toolbox.xaml"/>
        <ResourceDictionary Source="Resources/Connection.xaml"/>
        <ResourceDictionary Source="Resources/Slider.xaml"/>
        <ResourceDictionary Source="Resources/ScrollViewer.xaml"/>
        <ResourceDictionary Source="Resources/StatusBar.xaml"/>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
  </Application.Resources>
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

ResourceDictionary myResourceDictionary = new ResourceDictionary();
            myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\Shared.xaml");
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\ToolBar.xaml");
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\GroupBox.xaml");
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\ZoomBox.xaml");
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\ScrollBar.xaml");
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            myResourceDictionary.Source = new Uri("C:\\Resources\\Styles\\Expander.xaml");
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            myResourceDictionary.Source = new Uri("C:\\Resources\\ApplicationToolbar.xaml");
            Application.Current.Resources.MergedDictionaries.Add(myResourceDictionary);
            myResourceDictionary.Source …
Run Code Online (Sandbox Code Playgroud)

c# wpf resources

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

没有参数的RSASSA-PSS使用SHA-256 .Net 4.5支持

我正在尝试使用System.Security.Cryptography(目标框架.NET 4.5)来创建xml数字签名,到目前为止,我设法使用以下方案创建和验证签名:RSA PKCS#1 v1.5和SHA-256:http://www.w3.org/2001/04/xmldsig-more#rsa-sha256

但是,我无法使用以下方案:'没有使用SHA-256参数的RSASSA-PSS'[RFC6931]:http://www.w3.org/2007/05/xmldsig-more#sha256-rsa- MGF1

显示的错误很明显"无法为提供的签名算法创建SignatureDescription."

对于'RSA PKCS#1 v1.5和SHA-256',我添加了以下公共类作为其签名:

   public class RSAPKCS1SHA256SignatureDescription : SignatureDescription
   {
        public RSAPKCS1SHA256SignatureDescription()
        {
            base.KeyAlgorithm = "System.Security.Cryptography.RSACryptoServiceProvider";
            base.DigestAlgorithm = "System.Security.Cryptography.SHA256Managed";
            base.FormatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureFormatter";
            base.DeformatterAlgorithm = "System.Security.Cryptography.RSAPKCS1SignatureDeformatter";
        }

        public override AsymmetricSignatureDeformatter CreateDeformatter(AsymmetricAlgorithm key)
        {
            AsymmetricSignatureDeformatter asymmetricSignatureDeformatter = (AsymmetricSignatureDeformatter)
            CryptoConfig.CreateFromName(base.DeformatterAlgorithm);
            asymmetricSignatureDeformatter.SetKey(key);
            asymmetricSignatureDeformatter.SetHashAlgorithm("SHA256");
            return asymmetricSignatureDeformatter;
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是,我不知道.Net 4.5是否支持'使用SHA-256没有参数的RSASSA-PSS',如果是的话,如何设置其签名定义.

如果有人有类似的经验并能提供一些帮助,我会非常感激.

.net c# digital-signature signedxml xml-signature

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

实现 INotifyCollectionChanged 接口

我需要实现一个具有特殊功能的集合。另外,我想将此集合绑定到 ListView,因此我最终得到了下一个代码(我在论坛中省略了一些使其更短的方法):

public class myCollection<T> : INotifyCollectionChanged
{
    private Collection<T> collection = new Collection<T>();
    public event NotifyCollectionChangedEventHandler CollectionChanged;

    public void Add(T item)
    {
        collection.Insert(collection.Count, item);
        OnCollectionChange(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, item));
    }

    protected virtual void OnCollectionChange(NotifyCollectionChangedEventArgs e)
    {
        if (CollectionChanged != null)
            CollectionChanged(this, e);
    }
}
Run Code Online (Sandbox Code Playgroud)

我想用一个简单的数据类来测试它:

public class Person
{
    public string GivenName { get; set; }
    public string SurName { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

所以我创建了 myCollection 类的实例,如下所示:

myCollection<Person> _PersonCollection = new myCollection<Person>();
public myCollection<Person> PersonCollection
{ get { return _PersonCollection; } …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf observablecollection inotifycollectionchanged

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

WPF 控件中的标准键盘快捷键

我对 WPF 控件的所有可用快捷方式的列表感兴趣。我主要对 WPF TreeView 控件的标准快捷方式感兴趣(例如,全部展开/折叠、全选等),但我似乎找不到列出它们的任何位置。是否有特定页面列出了 WPF 控件的可用快捷方式?

我知道一些快捷方式是天真的支持的,例如,Ctrl+A将选择给定 ListView 控件中的所有行。

我可以定义自己的快捷方式并实现他们的行为。但是,我认为定义 .NET 框架已经支持的快捷方式并不是一个好的做法,因此需要了解此类支持的快捷方式。

在其他情况下,我通常会使用 Visual Studio 中可用的相同快捷方式,因为它是 WPF 应用程序,但我希望在这里获取 WPF 控件中开箱即用支持的快捷方式的更广泛列表。

c# wpf keyboard-shortcuts

0
推荐指数
1
解决办法
3018
查看次数