【发布时间】:2018-09-18 12:58:31
【问题描述】:
我有两个按钮,当我单击一个按钮时,我想使用 mvvm 更改另一个按钮 BackgroundColor
我正在努力做到这一点
<StackLayout>
<Button Text="Red" BackgroundColor="Accent" Command="{Binding ChangeButtons}" x:Name="btnRed"></Button>
<Button Text="Blue" x:Name="btnBlue"></Button>
</StackLayout>
当我点击btnRed 时,我希望更改btnBlue BackgroundColor。
模型视图页面
public class ButtonColorViewModel
{
public Command ChangeButtons
{
get
{
return new Command(() => {
//Change here button background colors
});
}
}
}
我该如何实现它?
【问题讨论】:
-
符合 MVVM,您将需要一个(如果您希望它们不同,则需要两个)代表背景颜色
-
我有 3 个按钮和 1 个 xaml 文件。点击 1 btn(或相反),我需要更改另一个 2 btns bg 颜色。
标签: c# xamarin mvvm xamarin.forms