我一直在寻找这个问题,发现放置一个含蓄TextBlock的风格Application.Resources是风格适用于所有的TextBlocks,即使是那些内如其他控件Buttons,ComboBoxes等等
<Application.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Blue" />
</Style>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
配售隐含的风格Window.Resources 不交叉控制模板的界限,所以像Buttons和ComboBoxes维持其默认的黑色文本.
<Window.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Blue" />
</Style>
</Window.Resources>
Run Code Online (Sandbox Code Playgroud)
此外,在其中添加默认样式Application.Resources使其无法用另一种隐式样式覆盖该样式.
<!-- Doesn't work if implicit style with same property is in Application.Resources -->
<ComboBox.Resources>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="Foreground" Value="Red" />
</Style>
</ComboBox.Resources>
Run Code Online (Sandbox Code Playgroud)
我的问题是:
Application.Resources和之间是否还有其他差异Windows.Resources?何时应该使用一个而不是另一个?
我理解这Application.Resources适用于整个应用程序,Window.Resources只适用于窗口,但我想知道为什么样式Application处理方式不同于样式Window
嗨,我在itemscontrol的datatemplate中只有一个文本框.当我将itemcontrols绑定到一个可观察的集合时,我得到两个文本框.但我需要根据每个文本框进行一些操作,我希望使用一些id分别找到每个文本框.
任何人都可以帮助如何在WPF中的itemscontrol中找到控件.