在 xaml 中引用基本类型控制模板

发布于 2024-08-13 15:41:05 字数 1106 浏览 1 评论 0原文

我有一个从 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 控件模板的内部成员,即 TextBoxPopup.通常我会在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枫林﹌晚霞¤ 2024-08-20 15:41:05

误报,

我没有在 generic.xaml 中包含指向此文件的链接哦

,而且我不必设置模板值,

   <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}" />
   </Style>

样式只会设置与基本样式不同的属性。因为我不想更改控件模板,所以我只是不设置它。 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

   <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}" />
   </Style>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文