因此,我正在使用 Fresh MVVM 在 Xamarin Forms 中制作应用程序,并且我希望在按下按钮时执行事件,并且仅当按钮的 BackgroundColor 为白色时才执行。按钮的 backgroundColor 将在 XAML.CS 中更改,而此事件将在 ViewModel 中发生。
问题是,在我拥有 ViewModel 属性的当前代码中,所有原色和属性都设置为 0,而不是实际的按钮颜色属性。我已经在寻找答案,但没有任何帮助。
下面是 XAML 代码:
<Button
x:Name="Button_NextStep"
HeightRequest="50"
WidthRequest="400"
BackgroundColor="{Binding NextStepBackgroundColor}"
CornerRadius="30"
Text="Next step"
TextColor="#4847FF"
FontAttributes="Bold"
FontSize="20"
VerticalOptions="Start"
HorizontalOptions="Start"
Margin="25,178,25,5"
Command="{Binding NextStep}"
></Button>
视图模型代码:
class CreateAccount_UsernameViewModel: FreshBasePageModel
{
public ICommand NextStep { get; set; }
public Color NextStepBackgroundColor { get; set; }
public InavigationService navigationService; //this is irrelevant for this question
public CreateAccount_UsernameViewModel(InavigationService _navService)
{
navigationService = _navService; //this is irrelevant for this question
NextStep = new Command(() =>
{
if (NextStepBackgroundColor == Color.FromHex("#FFD3D3D3"))
navigationService.SwitchNavigationStacks(Enums.NavigationStacks.CreateAccount, this); //this is irrelevant for this question
});
}
}
仅此而已,如果您需要更多信息来促进解决方案,我会在看到您的请求后立即提供给您。谢谢大家的时间,希望你有一个美好的一天。