6

以前の質問/回答で、Windows Phone のデータ バインディングが TypeConversionstringImageSource使用する方法を学びましたTypeConverterAttribute- https://stackoverflow.com/a/16753488/373321を参照してください

私は現在、TypeConverterAttribute 存在しないWindowsStore アプリで同じ問題を見ています。

WinRT データ バインディングを使用すると、明らかにデータ バインディング レイヤーは引き続き正しい変換を行うことができます。MSDN のドキュメントには次のように書かれています。

この動作は、文字列を URI として処理する基になる型変換に依存し、BitmapImage(Uri) コンストラクターに相当するものを呼び出します。

ただし、どの変換を行うかをどのように認識しているかについてのメタデータはどこにもありません。

私は独自のデータ バインディングの実装を構築しようとしています。そのため、WinRT の機能を模倣できると非常に便利です。

Xaml データ バインディングにどの変換を適用するかを指示する、クエリ可能なメタデータのヒントがどこかにありますか? それとも、CLR レイヤーから隠され、何らかの方法でランタイムに焼き付けられた変換ですかstring?ImageSource

非表示の場合、データバインディングの実装でキャッシュできるように、既知の自動型変換のリストがどこかにありますか?

4

2 に答える 2

2

この質問について、WinRT 開発者の 1 人 (Tim Heuer) と Twitter で話し合いました。

この会話の基本的な要約は次のとおりです。

  • WinRTには次のようなものはありませんTypeConverterAttribute
  • 少数の WinRT コントロールには、適用される少数の内部変換があります。
  • これらがどのコントロールと変換であるかについて公開されている情報はありません
于 2013-12-04T23:30:56.493 に答える
0

In Windows 8 Apps, this is generally handled by creating a class that inherits from IValueConverter, and is then assigned alongside the particular data binding. As stated on the msdn site:

"Create a converter by implementing the IValueConverter interface and implementing the Convert method. That method should return an object that is of the same type as the dependency property that the binding targets, or at least a type that can be implicitly coerced or converted to the target type."

Here is the link to the full doc: http://msdn.microsoft.com/en-US/library/windows/apps/windows.ui.xaml.data.binding.converter.aspx

See the "Examples" section for further detail.

To answer your question, there is no metadata hint, you simply create your converter and then explicitly assign the converter alongside your custom data binding.

于 2013-12-04T19:48:16.207 に答える