【问题标题】:WPF CheckBox is not checked when clicked between text and box在文本和框之间单击时未选中 WPF CheckBox
【发布时间】:2018-11-27 22:47:26
【问题描述】:

我有自定义样式的复选框,其中内容(文本)以 12,0,0,0 边距显示。所以框和文本之间的空间很小。

点击一个框或文本复选框后,被选中, 但是当我点击边距空间时没有任何反应。

有人知道问题出在哪里吗? 我将非常感谢任何答案。

【问题讨论】:

    标签: wpf checkbox controltemplate


    【解决方案1】:

    你是如何设置 CheckBox 的内容的?

    以下内容对我来说很好。

    <CheckBox Grid.Row="0">
        <TextBlock Margin="24,0,0,0" Text="Selected?"/>
    </CheckBox>
    

    【讨论】:

    • 我像往常一样设置内容:
    • 原因是我对 controlTemplate 的定义错误。它应该有 BulletDecorator 标签
    • 检查您的样式是否设置了 CheckBox 的 Background 属性。如果为空,则不会检测到鼠标点击。您可以改用透明。
    【解决方案2】:

    我发现我的自定义控件模板缺少 BulletDecorator 元素。

            <ControlTemplate TargetType="{x:Type CheckBox}">
                <BulletDecorator Background="Transparent">
                    <BulletDecorator.Bullet>
                        <Grid>
                          . . .
                        </Grid>
                    </BulletDecorator.Bullet>
                </BulletDecorator>
                <ControlTemplate.Triggers>
                    <Trigger Property="IsChecked" Value="True">
                          . . .
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-27
      • 2016-03-28
      • 2017-07-30
      • 2012-10-21
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      • 2020-08-14
      相关资源
      最近更新 更多