如何使用 IsEnabled 禁用 Expander 的一部分,而不是全部?
我有一个带有自定义模板的扩展器:
<ControlTemplate TargetType="{x:Type Expander}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Grid.Row="0">
<DockPanel>
<ToggleButton DockPanel.Dock="Right" Template="{DynamicResource ExpanderToggle}" />
<ContentPresenter DockPanel.Dock="Right" ContentSource="Tag" />
<ContentPresenter DockPanel.Dock="Left" ContentSource="Header">
</DockPanel>
</Border>
<Border Visibility="Collapsed" Grid.Row="1">
<ScrollViewer IsEnabled="True">
<ContentPresenter IsEnabled="{TemplateBinding IsEnabled}" />
</ScrollViewer>
</Border>
</Grid>
</ControlTemplate>
基本上,我试图这样做,以便如果我将 IsEnabled 属性设置为 false,我的滚动查看器仍然可以滚动(它保持启用状态,但控件的其他部分禁用)。有办法做到吗?
I have an expander with a custom template:
<ControlTemplate TargetType="{x:Type Expander}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Border Grid.Row="0">
<DockPanel>
<ToggleButton DockPanel.Dock="Right" Template="{DynamicResource ExpanderToggle}" />
<ContentPresenter DockPanel.Dock="Right" ContentSource="Tag" />
<ContentPresenter DockPanel.Dock="Left" ContentSource="Header">
</DockPanel>
</Border>
<Border Visibility="Collapsed" Grid.Row="1">
<ScrollViewer IsEnabled="True">
<ContentPresenter IsEnabled="{TemplateBinding IsEnabled}" />
</ScrollViewer>
</Border>
</Grid>
</ControlTemplate>
Basically, I'm attempting to make it so that if I set the IsEnabled property to false my scrollviewer still can scroll (it stays enabled, but other parts of my control disable). Any way to do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果 罗伯特的回答不起作用,您始终可以创建一个名为的
AttachedProperty
IsContentEnabled
并将 ContentPresenter 的 IsEnabled 绑定到该属性。If Robert's answer doesn't work, you could always create an
AttachedProperty
calledIsContentEnabled
and bind your ContentPresenter's IsEnabled to that property.为您的 DockPanel 命名。然后使用 e FindName (请参阅 http: //joshsmithonwpf.wordpress.com/2007/06/28/how-to-use-findname-with-a-contentcontrol/)来实现这一点运行时的 DockPanel。直接在其上设置 IsEnabled,而不是在更高级别的 Expander 控件上设置。如果合适的话,对您的 ContentPresenter 执行相同的操作。
Give your DockPanel a name. Then use e FindName (see http://joshsmithonwpf.wordpress.com/2007/06/28/how-to-use-findname-with-a-contentcontrol/) to get at that DockPanel at runtime. Set IsEnabled on it directly rather that on the higher level Expander control. Do the same for your ContentPresenter if appropriate.