English 中文(简体)
ResourceDictionary + StaticResource Alternative for organic System. XAML, no PresentationFramework
原标题:ResourceDictionary + StaticResource alternative for pure System.XAML, no PresentationFramework
  • 时间:2010-08-01 11:19:52
  •  标签:
  • .net

我愿享有<条码>。 ResourceDictionary +StaticResourceFunction, but without the need toload PresentationFramework - Inclusive System. Xaml。

我非常容易地把资源财产界定为一种词典,但我需要一种方式来提及那里的项目,即: 我需要<代码>StaticResource。 我看着这个词,似乎取决于WindowsBase和DonFramework的 st。

我不禁要问,是否还有另一种方式,却不忽略介绍框架。 我也理解,我可以从介绍框架中复制所有相关守则,只剩下最低限度支持所需功能——这是我最后的手段。

这里我直到现在才:

using System.Collections.Generic;
using System.Windows.Markup;
using System.Xaml;

namespace ConsoleApplication1
{
  [ContentProperty("Items")]
  public class XamlDictionary<TKey, TValue> : Dictionary<TKey, TValue>
  {
    public ICollection<KeyValuePair<TKey, TValue>> Items
    {
      get { return this; }
    }
  }

  public class A
  {
    private XamlDictionary<string, int> m_resources;
    public XamlDictionary<string, int> Resources 
    {
      get
      {
        if (m_resources == null)
        {
          m_resources = new XamlDictionary<string, int>();
        }
        return m_resources;
      }
      set { m_resources = value; }
    }
    public int Value { get; set; }
  }

  class Program
  {
    static void Main(string[] args)
    {
      var a = (A)XamlServices.Load("A.xaml");
    }
  }
}

<?xml version="1.0" encoding="utf-8" ?>
<l:A xmlns:scg="clr-namespace:System.Collections.Generic;assembly=mscorlib"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:sys="clr-namespace:System;assembly=mscorlib"
     xmlns:l="clr-namespace:ConsoleApplication1;assembly=ConsoleApplication1"
     Value="15">
  <l:A.Resources>
    <sys:Int32 x:Key="ssss">10</sys:Int32>
  </l:A.Resources>
</l:A>

迄今为止,一切都很好。 现在我想改动Xaml,以便A.Value reference the A.Resources[sss” Value,在此,我需要StaticResource替代物。

问题回答

您可能需要设立一个“科学资源扩展”作为标识=的一部分。





相关问题
Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How do I compare two decimals to 10 decimal places?

I m using decimal type (.net), and I want to see if two numbers are equal. But I only want to be accurate to 10 decimal places. For example take these three numbers. I want them all to be equal. 0....

Exception practices when creating a SynchronizationContext?

I m creating an STA version of the SynchronizationContext for use in Windows Workflow 4.0. I m wondering what to do about exceptions when Post-ing callbacks. The SynchronizationContext can be used ...

Show running instance in single instance application

I am building an application with C#. I managed to turn this into a single instance application by checking if the same process is already running. Process[] pname = Process.GetProcessesByName("...

How to combine DataTrigger and EventTrigger?

NOTE I have asked the related question (with an accepted answer): How to combine DataTrigger and Trigger? I think I need to combine an EventTrigger and a DataTrigger to achieve what I m after: when ...

热门标签