如何动态改变BackgroundColor的资源? [英] How to dynamically change resource of BackgroundColor?

查看:28
本文介绍了如何动态改变BackgroundColor的资源?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下控制权.我想更改某些事件触发器的背景颜色.我想将此 clrGray 资源作为某些事件点击的颜色.

I have following control. I want to change background color on some event trigger. I want to make this clrGray resource as color on some event click.

我尝试过以下方法,但没有用:(

I have tried by following way but it didn't work :(

XAM:

<local:RoundedFrame x:Name="MyFrame1" HeightRequest="16" IsVisible="True" BackgroundColor="{DynamicResource clrGreen}">

CS:

//On Some event
    //Not working
    MyFrame1.SetDynamicResource(MyFrame1.BackgroundColor, "clrGreen");

推荐答案

使用 Xamarin.Forms 动态资源.以下是 Xamarin 文档的链接:

Use Xamarin.Forms dynamic resources. Below is a link to the Xamarin documentation:

https://developer.xamarin.com/指南/xamarin-forms/user-interface/styles/dynamic/

它们非常易于使用/实施,并且完全符合您的要求.

They are very easy to use/implement, and do exactly what you want.

这篇关于如何动态改变BackgroundColor的资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆