1

我是 WPF 新手,我不知道该怎么做。我尝试了以下代码 -

<TextBlock Grid.Column="3" Grid.Row="3" Visibility="{Binding Path=CanCreate, Converter={StaticResource BoolVisibilityConverter}}">
     <Hyperlink KeyboardNavigation.TabIndex="2" Command="{Binding Path=CreateCommand}">Create 
         <Hyperlink.Style>
             <Style TargetType="{x:Type Hyperlink}">
                 <Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
                 <Style.Triggers>
                    <DataTrigger Binding="{Binding Path=CanCreate, Converter={StaticResource BoolVisibilityConverter}}">
                        <Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
                    </DataTrigger>
                 </Style.Triggers>
             </Style>
         </Hyperlink.Style>
    </Hyperlink>
</TextBlock>

可见性取决于 CanCreate Dependency 属性。此处 IsTabStop 未启用。任何人都可以提出解决方案。提前致谢。

要求

我想在 TabIndex 可见时将其设置为超链接。

4

1 回答 1

1

你不需要一个转换器来DataTrigger改变你Hyperlink.Style

<Hyperlink.Style>
      <Style TargetType="{x:Type Hyperlink}">
            <Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
            <Style.Triggers>
                 <DataTrigger Binding="{Binding Path=CanCreate}" Value="True">
                      <Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
                 </DataTrigger>
             </Style.Triggers>
       </Style>
</Hyperlink.Style>

编辑:您可能还想在您的TextBlockHyperlink不可见时移除焦点,您可以通过添加另一个来做到这一点DataTrigger

<Hyperlink.Style>
          <Style TargetType="{x:Type Hyperlink}">
                <Setter Property="KeyboardNavigation.IsTabStop" Value="False" />
                <Style.Triggers>
                     <DataTrigger Binding="{Binding Path=CanCreate}" Value="True">
                          <Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
                     </DataTrigger>
                     <DataTrigger Binding="{Binding Path=CanCreate}" Value="False">
                          <Setter Property="Focusable" Value="False" />
                     </DataTrigger>
                 </Style.Triggers>
           </Style>
    </Hyperlink.Style>
于 2013-07-03T08:56:47.000 回答