小编Mac*_*ito的帖子

WPF - 带按钮项的ComboBox

我有这个组合框,我想在其中添加按钮作为项目.但是,当我从组合框中选择按钮并单击按钮时,不会执行该操作.组合框的列表相反.该怎么做?如果这是不可能的,我想我只需要即兴发挥.建议将不胜感激.谢谢!

<ComboBox>
  <ComboBoxItem Name="Item1">
    <Button Name="Button1" Click="Button1_OnClick">first button</Button>
  </ComboBoxItem>
  <ComboBoxItem Name="Item2">
    <Button Name="Button2" Click="Button2_OnClick">second button</Button>
  </ComboBoxItem>
</ComboBox>
Run Code Online (Sandbox Code Playgroud)

c# wpf combobox button

2
推荐指数
1
解决办法
4560
查看次数

在 wpf 中的 StringFormat 内向字符串添加逗号

我有这个文本块

   <TextBlock>
      <TextBlock.Text>
        <MultiBinding StringFormat="{}{0}, {1}, {2}, ">
          <Binding Path="object.strProp1" />
          <Binding Path="object.strProp2" />
          <Binding Path="object.strProp3" />
        </MultiBinding>
      </TextBlock.Text>
    </TextBlock>
Run Code Online (Sandbox Code Playgroud)

假设object不为 null 且*strProp1* = "strProp1"*strProp2* = "strProp2"、 和*strProp2* = "strProp2"

其输出将是这样的:

strProp1, strProp2, strProp3,
Run Code Online (Sandbox Code Playgroud)

我想知道的是,每当对象为空或属性之一为空时,如何删除“,”。也就是说,如果object为 null,则 Textblock 将为空。或者,如果其中一个对象是空的,那么它就只是空的。

关于如何做到这一点有什么建议吗?谢谢!编辑:最好仅在 xaml 中:)

wpf xaml wpf-controls

2
推荐指数
1
解决办法
1664
查看次数

标签 统计

wpf ×2

button ×1

c# ×1

combobox ×1

wpf-controls ×1

xaml ×1