Button (如何)更改F#Fable Elmish中禁用按钮的字体颜色?

Button (如何)更改F#Fable Elmish中禁用按钮的字体颜色?,button,f#,fable-f#,elmish,Button,F#,Fable F#,Elmish,我尝试通过样式颜色设置颜色,但它仅在未禁用时更改颜色。 是否有可能使用或不使用Fulma Button.button [ Button.Disabled true Button.Props [ Style [ Color "#000000" ] ] //if … then Button.OnClick (fun _ -> dispatch Msg) ] [ str "Text h

我尝试通过样式颜色设置颜色,但它仅在未禁用时更改颜色。 是否有可能使用或不使用Fulma

Button.button
    [
        Button.Disabled true
        Button.Props [
            Style [ Color "#000000" ] ]
        //if … then
        Button.OnClick (fun _ -> dispatch Msg)
    ]
    [ str "Text here" ]
作为最后的手段,我会使用一个if条件和分派功能,这样就不用按钮了


提前感谢。

如果您只想更改禁用案例的字体颜色,您可以为此生成一种新样式:

Button.button
    [
        Button.Disabled isDisabled
        Button.Props [
            if isDisabled then yield Style [ Color "#000000" ] ]
        Button.OnClick (fun _ -> dispatch Increment)
    ]
    [ str "Text here" ]
如果要根据禁用状态使用不同的颜色,可以使用
If-then-else
表达式:

Button.button
    [
        Button.Disabled isDisabled
        Button.Props [
            Style [ (if isDisabled then Color "#000000" else Color "#ffffff") ] ]
        Button.OnClick (fun _ -> dispatch Increment)
    ]
    [ str "Text here" ]

@nilekirk解决方案确实是使用内联样式实现这一点的正确方法

但是,如果应用程序中有很多按钮,它会使代码很快变得非常冗长

另一个解决方案是将一些CSS直接应用于所有禁用的按钮,或者如果您不希望所有按钮都有这种行为,您可以添加一个自定义类

应用于应用程序的所有按钮

CSS代码:

.button[disabled] {
    background-color: black !important;
}
F#代码:

使用自定义类选择应具有此行为的按钮

CSS代码

.button.custom-disabled[disabled] {
    background-color: black !important;
}
F#代码


您好,谢谢您的提示,但我在编辑帖子代码时意外删除了禁用后的bool。它可以工作,但我想更改禁用状态下字体的颜色对不起,请问isDisabled是在哪里定义的,是如何定义的?VS告诉我,ist未定义Disabled是您定义的布尔值-很可能,它属于您的模型。谢谢,这很有效。让它更复杂一点:字体是否可能看起来不像被禁用的那样(禁用时颜色看起来仍然有点不稳定)。如果使用scss包含Bulma,则可以将
$按钮禁用的不透明度设置为1。如果没有,可以使用css将
不透明度设置为1。默认情况下,该值为0.5。使用以下行可获得额外的值:@import././../node_modules/bulma/sass/elements/button”;它起作用了。谢谢
.button.custom-disabled[disabled] {
    background-color: black !important;
}
Button.button
    [
        Button.CustomClass "custom-disabled"    
        Button.Disabled true
        Button.OnClick (fun _ -> dispatch Msg)
    ]
    [ str "Text here" ]