【发布时间】:2016-04-27 16:47:45
【问题描述】:
在我的上一个问题中,我将重新创建一个扩展器 + 它是切换按钮。
扩展模板:
<ControlTemplate TargetType="Expander">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="15"/>
</Grid.RowDefinitions>
<ContentPresenter x:Name="ContentPresenter" Grid.Row="0"/>
<ToggleButton Grid.Row="1" >
....
</ToggleButton>
</Grid>
现在,当我在主视图中使用此自定义控件并添加控件(例如按钮)时:
<custom:FullWidthExpander Width="200" HeaderBackground="Gray">
<Button />
</custom:FullWidthExpander>
ToggleButton(在我上面的扩展模板中定义)被此按钮覆盖。
【问题讨论】:
-
你确定被覆盖而不是被按钮隐藏了吗?您可以使用Snoop 准确查看控件在加载和运行时的样子。
-
是的,当窥探我的应用程序时,除了 ContentPresenter 之外的所有内容都丢失了:/
-
如果你给你的按钮设置一个尺寸,它还会出现吗?按钮采用所有可用尺寸,因此 Auto 可能是您的 Expander 尺寸
-
您的
ControlTemplate在哪里定义?我可以安全地假设FullWidthExpander是自定义UserControl吗?我在 MainWindow 中的 XAML 中使用普通 Expander 进行了快速测试,它工作得很好,所以我猜你的问题与你的控制层次结构有关。
标签: wpf xaml togglebutton templating expander