问题标签 [targettype]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
5 回答
18232 浏览

c# - 我可以在 WPF 中使用具有多个 TargetType 的样式吗?

如标题所示,我的意思如下:

这实际上是为了使用 3rd 方控件,我继承了他们的类。但是模板不适用于子类,因为TargetType它在基类上。所以我想设置多个TargetTypes 让它能够同时申请。

0 投票
1 回答
482 浏览

.net - 如果样式在 App.xaml 中连接,则按 TargetType 应用样式

例如,我有风格

在文件 Button.xaml 如果我使用 MergeDictionary 在我想使用它的文件中添加这种样式 - 一切都很好。但是,如果我在文件层次结构中将这种样式连接得更高(例如在 App.xaml 中)样式停止工作,直到我为它和所有按钮集设置 x:Key

样式=“{StaticResource name_of_style}”。

我可以避免这种行为还是必须按名称为我的所有元素样式设置?

0 投票
5 回答
6438 浏览

.net - when to use {x:Type …}?

What is the difference between:

and:

When and why do I need to use the {x:Type …} ?

0 投票
1 回答
1205 浏览

wpf - 当 DataTemplate 没有键,只有 TargetType 时从 ResourceDictionary 访问 DataTemplate

我在 XAML 中定义了一个带有代码隐藏的 ResouceDictionary。我需要使用鼠标事件和数据绑定定义一些特定于视图的行为,为此我需要访问在 DataTemplate 中定义的一些元素。

问题是,DataTemplate 没有 Key 它只有一个 TargetType(这是必需的,因此 WPF 将自动将其用于给定类型)。

那么,如何从代码隐藏中访问 DataTemplate?

编辑:

如果我在构造函数的某处放置一个断点,我可以看到我的 ViewModel 的模板就在那里。似乎 ResourceDictionary.Keys 属性是一个对象数组,而我要访问的键(或实际上是相应的值)在调试器中是这样的:

XAML:

代码隐藏:

0 投票
0 回答
150 浏览

c# - 为什么