Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How to get setting of Color in XAML-ResourceDictionary using C#,要怎麼在C#中讀取XAML-ResourceDictionary中的顏色

$
0
0

我有放了幾個顏色在ResourceDictionary中 如:
I use ResourceDictionary to pack some color settings,like

    <ResourceDictionary x:Name="The_Resources">
        <!--Global Styles-->
        <Color x:Key="color_A">#2196F3</Color>
        <Color x:Key="color_B">Khaki</Color>
        <Color x:Key="color_C">Coral</Color>

        <Style x:Key="Button_Style" TargetType="Button"    x:Name="Button_Style">
            <Setter Property="FontAttributes" Value="Bold" />
            <Setter Property="BackgroundColor" Value="{StaticResource color_B}" />
            <Setter Property="FontSize" Value="Default" />
        </Style>
      </ResourceDictionary >

C#可以用這樣的方式讀取ResourceDictionary的Style:
C# can get the Style in ResourceDictionary just like:

        Button 按鈕 = new Button
        {
            //BackgroundColor = Color.LightSteelBlue,
            Style = App.Current.Resources["Button_Style"] as Style,
        };

但要怎麼在C#中取得Colo_A B C的顏色賦予BackgroundColor呢?
but can C# read Color_A B C to set BackgroundColor?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>