2011-01-10 11 views
2

.NET 3.5SP1では、次のプロパティ設定のスタイルを使用しました。.NET 4.0ブレークイン変更 - XAMLスタイルのプロパティセッターの値としてのマークアップ拡張子の使用

<Setter Property="ToolTip" Value="{resource:Resource Group=Text, Key=BTN_CLOSE}"/> 

マークアップ拡張は、私たちの衛星アセンブリにアクセスし、ツールチップの適切なリソーステキストを取得します。これがこのように行われる理由は、アプリケーションがカスタマイズ可能であるためです。マークアップ拡張機能を使用すると、クライアントはキーの組み合わせを使用してテキストのキーを表示し、そうすることを選択するとテキスト値を変更できます。

.NET 4.0にアップグレードした後、上記のxamlがボタンスタイルのツールチップを定義すると、以下のエラーが発生します。これを行う別の方法はありますか?

System.Windows.Markup.XamlParseException: A 'Binding' cannot be set on the 
'Value' property of type 'Setter'. A 'Binding' can only be set on a 
DependencyProperty of a DependencyObject. 
at System.Windows.Markup.XamlReader.RewrapException(Exception e, Uri baseUri) 
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlReader templateReader, XamlObjectWriter currentWriter) 
at System.Windows.FrameworkTemplate.LoadTemplateXaml(XamlObjectWriter objectWriter) 
at System.Windows.FrameworkTemplate.LoadOptimizedTemplateContent(DependencyObject container, IComponentConnector componentConnector, IStyleConnector styleConnector, List`1 affectedChildren, UncommonField`1 templatedNonFeChildrenField) 
at System.Windows.FrameworkTemplate.LoadContent(DependencyObject container, List`1 affectedChildren) 
at System.Windows.StyleHelper.ApplyTemplateContent(UncommonField`1 dataField, DependencyObject container, FrameworkElementFactory templateRoot, Int32 lastChildIndex, HybridDictionary childIndexFromChildID, FrameworkTemplate frameworkTemplate) 
at System.Windows.FrameworkTemplate.ApplyTemplateContent(UncommonField`1 templateDataField, FrameworkElement container) 
at System.Windows.FrameworkElement.ApplyTemplate() 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Canvas.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV) 
at System.Windows.Controls.Grid.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint) 
at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Documents.AdornerDecorator.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Controls.Border.MeasureOverride(Size constraint) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Window.MeasureOverrideHelper(Size constraint) 
at System.Windows.Window.MeasureOverride(Size availableSize) 
at System.Windows.FrameworkElement.MeasureCore(Size availableSize) 
at System.Windows.UIElement.Measure(Size availableSize) 
at System.Windows.Interop.HwndSource.Process_WM_SIZE(UIElement rootUIElement, IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam) 
at System.Windows.Interop.HwndSource.LayoutFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 

私はキー要素を除外したと思います。テキストとキーとの間のスワップを可能にするために、値を格納するResourceCacheクラスがあります。提供値では、ツールチップのバインドを破っている部分は、binding.ProvideValue(serviceProvider)を返すという事実です。これは.NET 3.5SP1の場合と同じです。

public override object ProvideValue(IServiceProvider serviceProvider) 
{ 
    ResourceCache resourceCache = ResourceCache.Instance; 
    resourceCache["cacheKey"] = "hello"; 

    Binding binding; 

    binding = new Binding(); 
    binding.Source = resourceCache; 
    binding.Path = new PropertyPath("[" + "cacheKey" + "]"); 
    binding.Mode = BindingMode.OneWay; 

    return binding.ProvideValue(serviceProvider); 
} 
+0

XAMLが質問に表示されませんでした。 XAMLの各行の先頭に4つのスペースを追加します。 –

答えて

関連する問題