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

  • Question

  • User384128 posted

    ?????????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#???ColoA B C?????BackgroundColor?? but can C# read ColorA B C to set BackgroundColor?

    Tuesday, April 16, 2019 1:24 AM

Answers

  • User371688 posted

    You can use like this:

    BackgroundColor = (Color)Application.Current.Resources["color_A"];
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 16, 2019 2:40 AM
  • User371688 posted

    @ClawRage Have you resolved your problem?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, April 19, 2019 3:01 AM

All replies

  • User371688 posted

    You can use like this:

    BackgroundColor = (Color)Application.Current.Resources["color_A"];
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Tuesday, April 16, 2019 2:40 AM
  • User371688 posted

    @ClawRage Have you resolved your problem?

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, April 19, 2019 3:01 AM