2011-07-11 19 views

答えて

1

私はMSDN linkがこれを説明するのに良いと思います。また

「アンビエント型(AmbientAttributeタイプレベルで適用されるタイプの)プロパティのタイプは、順不同で解決される必要がある特定のXAML処理の状況に使用することができ、上記ページ内の行を参照"

そしてこのlink氏は述べています

「AmbientAttributeは、アプリケーション、セッター、およびスタイルを含め、いくつかのWPFの種類、のメンバーに記載されています。また、暗示ResourceDictionaryの種類に発見されているようなのResourceDictionaryを使用して任意のメンバーメンバーが特別に帰属されていなくても、そのタイプは周囲環境とみなされるべきです。

1

あなたが正しい型の値にVをtypeconvertする方法を理解する前に、P(Pの実際のタイプを)知っている必要があります
<Setter Property="P" Value="V" />
のような問題を解決するために使用されます。 "Property"プロパティを[Ambient]とマークし、1.ローダーが最初に "Property"を処理し、2. "Value"型コンバータが実行時に "Type"値を読み取ることを許可します。
これは、{StaticResource foo}がXAMLの親を検索し、その中に "foo"が含まれている可能性のあるResourceDictionaryを探す方法です。

例:

// This markup extension returns the number of Ambient "Resource" properties 
// Found in the XAML tree above it. 
// The FrameworkElement.Resources property is already marked [Ambient] 
public class MyMarkupExtension : MarkupExtension 
{ 
    public override object ProvideValue(IServiceProvider serviceProvider) 
    { 
     var schemaProvider = serviceProvider.GetService(typeof(IXamlSchemaContextProvider)) as IXamlSchemaContextProvider; 
     var ambientProvider = serviceProvider.GetService(typeof(IAmbientProvider)) as IAmbientProvider; 
     XamlMember resourcesProperty = new XamlMember(typeof(FrameworkElement).GetProperty("Resources"), schemaProvider.SchemaContext); 
     List<AmbientPropertyValue> resources = (List<AmbientPropertyValue>) ambientProvider.GetAllAmbientValues(null, resourcesProperty); 
     Debug.WriteLine("found {0} FramewrkElement.Resources Properties", resources.Count); 
     return resources.Count.ToString(); 
    } 
} 
関連する問題