Silverlight 4.0 如何覆盖Silverlight应用程序中的文本块IshitteVisible

Silverlight 4.0 如何覆盖Silverlight应用程序中的文本块IshitteVisible,silverlight-4.0,textblock,Silverlight 4.0,Textblock,我将保留我的观点,他们为什么这样做,在其他地方咆哮,所以 我试图阻止文本块在我的Silverlight应用程序中获得焦点。在我的应用程序的基本页面类(页面继承)中的任何文本块上添加此属性的setter似乎有一定的意义,但1)我可能错了,2)我似乎不能完全正确 我尝试过添加如下代码: this.Style.Setters.Add(new Setter(TextBlock.IsHitTestVisibleProperty, false)); <Application xm

我将保留我的观点,他们为什么这样做,在其他地方咆哮,所以

我试图阻止文本块在我的Silverlight应用程序中获得焦点。在我的应用程序的基本页面类(页面继承)中的任何文本块上添加此属性的setter似乎有一定的意义,但1)我可能错了,2)我似乎不能完全正确

我尝试过添加如下代码:

        this.Style.Setters.Add(new Setter(TextBlock.IsHitTestVisibleProperty, false));
<Application
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  x:Class="YourApp.App"
  mc:Ignorable="d">

    <Application.Resources>
        <ResourceDictionary>
            <Style TargetType="TextBlock">
                <Setter Property="IsHitTestVisible" Value="False" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>
我的应用程序的基本页面类的构造函数(直接从页面继承)或在页面加载的事件处理程序中。但是这个主题的大多数变体似乎都不起作用(通常看起来好像所有正确的成员都还不存在或者XamlParseException)


这可能是荒谬的简单,但我的大脑显然也是如此。有什么想法吗?

你可以用一种含蓄的风格

<Style TargetType="TextBlock">
   <Setter Property="IsHitTestVisible" Value="False" />
</Style>

通常,如果在单独的资源字典中,样式会合并到App.xaml文件的顶层,或者您可以在那里简单地添加样式。我本人对Silverlight非常陌生,所以我只报告我所看到的

假设您有一个空的App.xaml启动,它可能如下所示:

        this.Style.Setters.Add(new Setter(TextBlock.IsHitTestVisibleProperty, false));
<Application
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
  x:Class="YourApp.App"
  mc:Ignorable="d">

    <Application.Resources>
        <ResourceDictionary>
            <Style TargetType="TextBlock">
                <Setter Property="IsHitTestVisible" Value="False" />
            </Style>
        </ResourceDictionary>
    </Application.Resources>
</Application>


这是一个非常简单的测试,你可以添加一个前景色设置器,看看你的所有文本块是否都采用了这种风格。

谢谢,马克。请原谅我的XAML noobiness,但我使用的基本页面类是一个cs文件。所有页面如何继承你布置的XAML?你可能已经有或可能没有样式资产。这些通常是合并我将尝试进行一次基本的编辑来解决这个问题。