在 xaml 中引用基本类型控制模板
我有一个从 ComboBox
派生的控件,我想使用 ComboBox
ControlTemplate
,只需在 xaml 中设置几个值,即ItemContainerStyle
。下面的代码不起作用,最后一个设置器(我打算将基本 ComboBox
控件模板应用于此设置器)不会执行任何操作。
<Style
TargetType="{x:Type local:EditingFilteringComboBox}"
BasedOn="{StaticResource {x:Type ComboBox}}">
<Setter
Property="IsEditable"
Value="False" />
<Setter
Property="DisplayMemberPath"
Value="DisplayValue" />
<Setter
Property="ItemContainerStyle"
Value="{StaticResource editingFilteringComboBoxListBoxItem}" />
<Setter
Property="Template"
Value="{StaticResource {x:Type ComboBox}}" />
</Style>
我想从 ComboBox
派生,但我不想包含它的整个控件模板。我什至不想碰控制模板。我确实想更改 ItemContainerStyle
,我可以通过代码来完成此操作,但如果不需要的话会更好。
我在这里想要这个的另一个原因是因为想要访问 ComboBox
控件模板的内部成员,即 TextBox
和 Popup.通常我会在
OnApplyTemplate
的重写中访问这样的成员。
我感觉自己走错路了,请老师赐教。
I have a control derived from ComboBox
, I want to use the ComboBox
ControlTemplate
, and just set a few values on it in xaml, namely the ItemContainerStyle
. The code below doesn't work, the last setter, which im intending to apply the base ComboBox
control template to this one, doesn't do anything.
<Style
TargetType="{x:Type local:EditingFilteringComboBox}"
BasedOn="{StaticResource {x:Type ComboBox}}">
<Setter
Property="IsEditable"
Value="False" />
<Setter
Property="DisplayMemberPath"
Value="DisplayValue" />
<Setter
Property="ItemContainerStyle"
Value="{StaticResource editingFilteringComboBoxListBoxItem}" />
<Setter
Property="Template"
Value="{StaticResource {x:Type ComboBox}}" />
</Style>
I want to derive from ComboBox
but I dont want to include the whole control template for it. I dont even want to touch the control template. I do want to change the ItemContainerStyle
, which I could do from code, but much nicer if i dont have to.
The other reason why I want this here is because to want access to the internal members of the ComboBox
's control template, namely the TextBox
and the Popup
. Usually I access members like this in the override of OnApplyTemplate
.
I feel like im travelling the wrong path, enlighten me sensei.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
误报,
我没有在 generic.xaml 中包含指向此文件的链接哦
,而且我不必设置模板值,
样式只会设置与基本样式不同的属性。因为我不想更改控件模板,所以我只是不设置它。 OnApplyTemplate 被调用,我可以访问 ComboBox 控件模板的内部结构。
false alarm,
i wasnt including a link to this file in my generic.xaml
oh and i didnt have to set the Template value
the style will only set properties that are different from the base style. so as i dont want to change the control template i simply dont set it. OnApplyTemplate is called, and i can access the internals of the ComboBox's control template.