开发者

In WPF, how do I bind a textbox style to two different styles that toggle on a button click?

I'm working in a MVVM paradigm, and I'm trying to get a 开发者_运维百科textbox to change styles when a button is triggered.

I have a file named TextBoxStyles and think that I might be creating a placeholder style that has a trigger that changes based on a back end boolean. Correct me if I'm wrong but the backend boolean is really straight forward:

public void ChangeStyleButtonBoolean()
{
    _changeStyleButtonBoolean = true;
}

But how do I: 1) bind the style to this boolean, and 2) then select two different styles based on that boolean?


Could you use a toggle button and have a trigger? We're currently doing something similar by changing the image inside of the template for a toggle button. Something like this:

<ControlTemplate x:Key="LightBulbToggleButtonTemplate" TargetType="{x:Type ToggleButton}">
    <Image Name="LightBulbButton" Source="{StaticResource LightBulbOn}" Width="24" Height="24" Cursor="Hand" />

    <ControlTemplate.Triggers>
        <Trigger Property="IsChecked" Value="True">
            <Setter Property="Source" Value="{StaticResource LightBulbOn}" TargetName="LightBulbButton"/>
        </Trigger>
        <Trigger Property="IsChecked" Value="False">
            <Setter Property="Source" Value="{StaticResource LightBulbOff}" TargetName="LightBulbButton"/>
        </Trigger>
    </ControlTemplate.Triggers>

</ControlTemplate>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜