触发对话框“应用”按钮状态

发布于 2024-08-11 00:25:59 字数 1345 浏览 4 评论 0原文

我想当此对话框中某些文本框的内容发生更改时启用“应用”对话框按钮。

这是我的想法:

<Window.Resources>
    <ResourceDictionary>
        ...
        <Style x:Key="SettingTextBoxStyle" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="TextBox.TextChanged" >

                    <!-- I need something like this -->
                    <Setter Property="ApplyButton.IsEnabled" Value="True" />

                </EventTrigger>
            </Style.Triggers>
        </Style>
    </ResourceDictionary>
</Window.Resources>

<!-- in a galaxy far far away -->
<StackPanel>
        ...
        <TextBox Style="{StaticResource SettingTextBoxStyle}" Text="{Binding Source={x:Static settings:Settings.Default}, Path=OutputFile}"  />
</StackPanel>

<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right">
    <Button Content="OK" Width="100" Click="OK_Click"/>
    <Button Content="Cancel" Width="100" Click="Cancel_Click" />
    <Button Content="Apply" Name="ApplyButton" Width="100" Click="Apply_Click"/>
</StackPanel>

如何在事件触发器中访问 ApplyButton.IsEnabled 属性?

我是否应该在后台代码中使用相同的 TextChanged 事件处理程序来代替所有这些?

还是别的什么?

I want to enable 'Apply' dialog button when content of some textboxes in this dialog changes.

Here is what I came up with:

<Window.Resources>
    <ResourceDictionary>
        ...
        <Style x:Key="SettingTextBoxStyle" TargetType="{x:Type TextBox}">
            <Style.Triggers>
                <EventTrigger RoutedEvent="TextBox.TextChanged" >

                    <!-- I need something like this -->
                    <Setter Property="ApplyButton.IsEnabled" Value="True" />

                </EventTrigger>
            </Style.Triggers>
        </Style>
    </ResourceDictionary>
</Window.Resources>

<!-- in a galaxy far far away -->
<StackPanel>
        ...
        <TextBox Style="{StaticResource SettingTextBoxStyle}" Text="{Binding Source={x:Static settings:Settings.Default}, Path=OutputFile}"  />
</StackPanel>

<StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal" HorizontalAlignment="Right">
    <Button Content="OK" Width="100" Click="OK_Click"/>
    <Button Content="Cancel" Width="100" Click="Cancel_Click" />
    <Button Content="Apply" Name="ApplyButton" Width="100" Click="Apply_Click"/>
</StackPanel>

How do I reach ApplyButton.IsEnabled property in my event trigger?

Should I instead all of this simply use same TextChanged event handler in back code?

Or something else?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧话新听 2024-08-18 00:25:59

你可以试试这个:

<Grid>
    <TextBox Name="textBox" Height="28" VerticalAlignment="Top" HorizontalAlignment="Left" Width="95" >
        <TextBox.Triggers>
            <EventTrigger RoutedEvent="TextBox.TextChanged">
                <BeginStoryboard>
                    <Storyboard>
                        <BooleanAnimationUsingKeyFrames Storyboard.TargetName="button1" Storyboard.TargetProperty="(Button.IsEnabled)">
                            <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
                        </BooleanAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </TextBox.Triggers>
    </TextBox>              
    <Button Height="26" Width="150" IsEnabled="false" Name="button1">Button</Button>
</Grid>

you can try this:

<Grid>
    <TextBox Name="textBox" Height="28" VerticalAlignment="Top" HorizontalAlignment="Left" Width="95" >
        <TextBox.Triggers>
            <EventTrigger RoutedEvent="TextBox.TextChanged">
                <BeginStoryboard>
                    <Storyboard>
                        <BooleanAnimationUsingKeyFrames Storyboard.TargetName="button1" Storyboard.TargetProperty="(Button.IsEnabled)">
                            <DiscreteBooleanKeyFrame KeyTime="00:00:00" Value="True"/>
                        </BooleanAnimationUsingKeyFrames>
                    </Storyboard>
                </BeginStoryboard>
            </EventTrigger>
        </TextBox.Triggers>
    </TextBox>              
    <Button Height="26" Width="150" IsEnabled="false" Name="button1">Button</Button>
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文