首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AdornerDecorator和制表位问题

AdornerDecorator和制表位问题
EN

Stack Overflow用户
提问于 2008-12-10 00:20:34
回答 1查看 3.3K关注 0票数 3

我正在使用IDataErrorInfo来验证和指出文本框中的错误。我发现我必须为文本框设置一次tab键,为装饰器设置一次tab键。

我有一个错误模板:

代码语言:javascript
复制
<ControlTemplate x:Key="ErrorTemplate">
        <StackPanel KeyboardNavigation.IsTabStop="False" >
        <Border KeyboardNavigation.IsTabStop="False"  BorderBrush="Red" BorderThickness="1" Padding="2" CornerRadius="2">
            <AdornedElementPlaceholder KeyboardNavigation.IsTabStop="False" />
        </Border>
        </StackPanel>                
    </ControlTemplate>

文本框模板:

代码语言:javascript
复制
<Style x:Key="TextBoxInError" TargetType="{x:Type TextBox}">
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="Margin" Value="0,5,0,5"/>
        <Setter Property="AllowDrop" Value="true"/>
        <Setter Property="HorizontalContentAlignment" Value="left"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Grid  KeyboardNavigation.IsTabStop="False" >
                        <Border  KeyboardNavigation.IsTabStop="False" x:Name="Border" Background="{DynamicResource WindowBackgroundBrush}" BorderBrush="{DynamicResource SolidBorderBrush}" BorderThickness="1" Padding="2" CornerRadius="2">
                            <ScrollViewer IsTabStop="False" Margin="0" x:Name="PART_ContentHost" Style="{DynamicResource SimpleScrollViewer}" Background="{TemplateBinding Background}"/>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Validation.HasError" Value="true">
                            <Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors), Converter={StaticResource errorConverter}}"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground" Value="Gray"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

并像这样声明一个文本框:

代码语言:javascript
复制
<AdornerDecorator  KeyboardNavigation.IsTabStop="False" >
<TextBox Margin="5,5,5,3" x:Name="txtName" IsEnabled="{Binding EditMode}" Validation.ErrorTemplate="{StaticResource ErrorTemplate}"
 Text="{Binding ApplicationName, Mode=TwoWay, ValidatesOnExceptions=True, NotifyOnValidationError=True, ValidatesOnDataErrors=True}" 
 Height="25" MaxLength="50" MaxLines="1" Style="{StaticResource TextBoxInError}"/>
 </AdornerDecorator>

如果装饰器像上面那样围绕一个文本框,那么我按tab键一次离开文本框,一次离开“装饰”(看起来)如果装饰器围绕着一堆文本框,那么每个文本框都要按一次tab键,然后必须依次返回所有的“装饰”。当用the键切换装饰物时,焦点位于控件模板中定义的红色边框上。

有什么想法吗?

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2008-12-10 08:39:43

将此代码添加到窗口的资源部分:

代码语言:javascript
复制
<Style TargetType="{x:Type Control}">
    <Setter Property="Focusable" Value="False"/>
</Style>

有关更多信息,请查看我的博客:http://www.nbdtech.com/blog/archive/2008/05/25/WPF-Problems-with-Keyboard-Focus-When-Using-Validation.aspx

票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/354717

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档