0

Windows ストア アプリ用の VB.NET で使用できる FromName メソッドはありません。文字列を色に変換するにはどうすればよいですか? 色の文字列値を渡して、オブジェクトの塗りつぶし色を設定したいと考えています。

C#のこの回避策を見つけました

public static Color FromName(string name)
{
     var property = typeof(Colors).GetRuntimeProperty(name);
     return (Color)property.GetValue(null);
}

それを同等の VB.NET コードに変換できないようです。

また、上記のコードを使用して Windows ランタイム コンポーネントを記述しようとしましたが、GetRunTimeProperty がどこにも定義されていないと表示されます。

4

3 に答える 3

2
Public Function FromName(ColName As String) As SolidColorBrush
        Dim [property] = System.Reflection.RuntimeReflectionExtensions.GetRuntimeProperty(GetType(Windows.UI.Colors), ColName)
        Return New SolidColorBrush(DirectCast([property].GetValue(Nothing), Windows.UI.Color))
End Function

そして完了!

于 2013-07-17T03:49:43.590 に答える
0

これは機能しませんか?

Public Shared Function FromName(name As String) As Color
    Dim [property] = GetType(Colors).GetRuntimeProperty(name)
    Return DirectCast([property].GetValue(Nothing), Color)
End Function
于 2013-07-17T03:17:08.757 に答える