如何创建不会自动应用的样式?

How can I create a style that is not automatically applied?

In this answer 它被(正确地?它似乎..)声称如果你省略 x:Name 属性,样式会自动应用到任何地方。

If you don't specify an identifier on each Style, that style will apply to all controls that match with the TargetType you specified. If you want button to look different, you can do the same as above, but also include an identifier to that style, that will be used by each different button: [...]

但是,当我添加 x:Name 标识符时,它应该不会自动应用,还是应该自动应用?

因为当我尝试这个时:

<Style TargetType="{x:Type TextBlock}" x:Name="RunningTextStyle">
    <Setter Property="FontSize" Value="15" />
</Style>

在我的 ResourceDictionary 中以这种方式链接到我的 app.xaml

<Application.Resources>
    <ResourceDictionary Source="ApplicationStyles.xaml" />
</Application.Resources>

它仍然会自动应用于所有 TextBlock

如何创建必须与其标识符一起使用才能显示的样式?

我在 VS2015 中使用 Resharper,当我尝试以这种方式手动将样式添加到 TextBlock 时,x:Key 名称甚至没有显示:Style="{StaticResource ...}" 定义为可能性(我曾经以这种方式获得过它并且确实如此。它有效,但通常它是由 R# 或 VS 宣传使用的)。

有趣的是,就在几个小时前,我的 Button 样式没有自动应用。

给样式一个 x:Key="MyArbitraryStyleKey" 属性。它在 ResourceDictionary 中,而字典中某个事物的 "name"(可以说是比喻)称为键,当您这样看时,它确实有意义。在功能上,在 XAML、x:Namex:Key 中调用不同的代码以非常不同的方式做不同的事情,即使一开始语义差异感觉有点模糊。

<Style TargetType="{x:Type TextBlock}" x:Key="RunningTextStyle">
    <Setter Property="FontSize" Value="15" />
</Style>

...

<TextBlock 
    Style="{StaticResource RunningTextStyle}" 
    Text="I tried Resharper once. Sent them back their demo, tied to a brick."
    />

如果 Resharper 不喜欢它,请向他们发送错误报告(嘿,事实证明 Resharper 很喜欢它——我收回我所说的一切!)

只需使用 x:Key="RunningTextStyle" 而不是 x:Name="RunningTextStyle"