如何使用 IsEnabled 禁用 Expander 的一部分,而不是全部?

发布于 2024-12-10 21:56:29 字数 1073 浏览 0 评论 0原文

我有一个带有自定义模板的扩展器:

<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 技术交流群。

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

发布评论

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

评论(2

深爱不及久伴 2024-12-17 21:56:29

如果 罗伯特的回答不起作用,您始终可以创建一个名为的 AttachedProperty IsContentEnabled 并将 ContentPresenter 的 IsEnabled 绑定到该属性。

<Expander local:IsContentEnabled="False" />

<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>
                <ContentPresenter IsEnabled="{TemplateBinding local:IsContentEnabled}" />
            </ScrollViewer>
        </Border>
    </Grid>
</ControlTemplate>

If Robert's answer doesn't work, you could always create an AttachedProperty called IsContentEnabled and bind your ContentPresenter's IsEnabled to that property.

<Expander local:IsContentEnabled="False" />

<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>
                <ContentPresenter IsEnabled="{TemplateBinding local:IsContentEnabled}" />
            </ScrollViewer>
        </Border>
    </Grid>
</ControlTemplate>
蓝海似她心 2024-12-17 21:56:29

为您的 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.

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