1

我试图在我的表单中向某些文本框添加属性。我正在做的是当用户专注于某些领域时,我想放置 blur 属性。这是下面的代码。当我做错了什么时请告诉我。

textbox.Attributes.Add("onfocus()", "blur")

4

1 回答 1

0

这是一个简单的 WPF 示例。单击该按钮将模糊和取消模糊两个文本框。

我希望这能为您指明正确的方向。

XAML:

<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="188" Width="373">
<Grid>
    <Grid.ColumnDefinitions>
        <ColumnDefinition/>
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
    </Grid.RowDefinitions>

    <TextBox Name="textBoxOne" Grid.Column="0" Grid.Row="0" Margin="10,4" Text="TextBoxBase One"/>
    <TextBox Name="textBoxTwo" Grid.Column="0" Grid.Row="1" Margin="10,4" Text="TextBoxBase Two"/>
    <TextBox Name="textBoxThree" Grid.Column="0" Grid.Row="2" Margin="10,4" Text="TextBoxBase Three"/>
    <TextBox Name="textBoxFour" Grid.Column="0" Grid.Row="3" Margin="10,4" Text="TextBoxBase Four"/>

    <Button Grid.Column="0" Grid.Row="4" Content="Toggle Blur" Click="ToggleBlur_Click"/>
</Grid>

编码:

Class MainWindow
    Private _ToggleBlurOnOff As Boolean = False

    Private Sub ToggleBlur_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        _ToggleBlurOnOff = Not _ToggleBlurOnOff
        If (_ToggleBlurOnOff) Then
            Dim blur As Effects.BlurEffect = New Effects.BlurEffect()
            blur.Radius = 5
            textBoxOne.Effect = blur
            textBoxThree.Effect = blur
        Else
            textBoxOne.Effect = Nothing
            textBoxThree.Effect = Nothing
        End If
    End Sub
End Class

我相信您专门寻找的代码是:

Dim blur As Effects.BlurEffect = New Effects.BlurEffect() 
blur.Radius = 5 
textBoxOne.Effect = blur 
于 2012-07-16T20:23:33.377 回答