添加运行时标签作为复选框 wpf 中的内容

发布于 2024-09-10 03:51:35 字数 190 浏览 1 评论 0原文

我在运行时动态创建复选框,并在运行时应用样式。设计者开发了一个类似复选框的控件,可以在运行时应用。他在该复选框控件上放置了一个标签,以将复选框控件上的文本显示为数据库中的内容。但是,当我在运行时应用复选框或标签的内容时,它显示在设计者开发的复选框控件的后面。如何使用 Label 控件在复选框控件上显示数据库中的内容。

请建议?

谢谢

I am dynamically creating the checkboxes at runtime and also applying the style at runtime. Designer has developed a checkbox like control that am applying at runtime. and he put a Label on that checkbox control to show the Text on the checkbox control as its content from the Database. But when i applying content of checkbox or label at runtime, it displays at the back of that checkbox control that is developed by the designer. How to make use of the Label control to show the content from the database on the checkbox control.

Kindly Suggest?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

网白 2024-09-17 03:51:35

在我看来,您的设计师忘记在他的复选框模板中包含 。如果没有 ContentPresenter,您添加为评论的文本将永远不会显示。

以下是包含所需 ContentPresenter 的自定义 CheckBox ControlTemplate 的示例:

<ControlTemplate TargetType="{x:Type CheckBox}">
  <DockPanel>
    <Border BorderThickness="1" BorderBrush="Black">
      <Path x:Name="check" Width="10" Height="10"
            Data=".... data for checkmark in checkbox ..." />
    </Border>
    <ContentPresenter/>
  </DockPanel>
  <ControlTemplate.Triggers>
    <Trigger ... trigger for changing checkmark ... />
  </ControlTemplate.Triggers>
</ControlTemplate>

It sounds to me like your designer forgot to include a <ContentPresenter/> in his checkbox template. If there is no ContentPresenter, the text you add as a comment will never be shown.

Here is an example of a custom CheckBox ControlTemplate that includes the required ContentPresenter:

<ControlTemplate TargetType="{x:Type CheckBox}">
  <DockPanel>
    <Border BorderThickness="1" BorderBrush="Black">
      <Path x:Name="check" Width="10" Height="10"
            Data=".... data for checkmark in checkbox ..." />
    </Border>
    <ContentPresenter/>
  </DockPanel>
  <ControlTemplate.Triggers>
    <Trigger ... trigger for changing checkmark ... />
  </ControlTemplate.Triggers>
</ControlTemplate>
蘸点软妹酱 2024-09-17 03:51:35

您应该检查您的复选框样式。它应该是复选框标记下样式 liyng 的标签(文本框)。以下是 chekcbox 模板的几乎正确的代码:

<Grid>
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="Auto"/>
       <ColumnDefinition Width="*"/>
   </Grid.ColumnDefinitions>
   <Border Grid.Column="0">
      <!--Place your mark here-->
   </Border>
   <Border Grid.Column="1">
      <!--Place your label here-->
   </Border>
</Grid>

You should to review your checkbox style. It is supposed to be that label(textbox) in style liyng under checkbox mark. Here is nearly right code for the chekcbox template:

<Grid>
   <Grid.ColumnDefinitions>
       <ColumnDefinition Width="Auto"/>
       <ColumnDefinition Width="*"/>
   </Grid.ColumnDefinitions>
   <Border Grid.Column="0">
      <!--Place your mark here-->
   </Border>
   <Border Grid.Column="1">
      <!--Place your label here-->
   </Border>
</Grid>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文