如何在wpf中将常量值附加到组合框的显示成员?

时间:2013-06-30 17:51:33

标签: c# .net wpf

我关注了wpf组合框:

<dxe:ComboBoxEdit x:Name="cmbCommissionTier" ItemsSource="{Binding ListCommissionTier, Mode=TwoWay}" SelectedItem="{Binding SelectedCommissionTier, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" DisplayMember="CommissionValue">

DisplayMember="CommissionValue"中,CommissionValue是包含值10的属性。但是我想在组合框中显示10%。如何将此%附加到组合框的显示成员?

3 个答案:

答案 0 :(得分:3)

ItemStringFormat应该有效,例如{}{0}%

答案 1 :(得分:3)

您需要在组合框上设置ItemStringFormat -

<dxe:ComboBoxEdit x:Name="cmbCommissionTier"
                  ItemsSource="{Binding ListCommissionTier, Mode=TwoWay}"
                  SelectedItem="{Binding SelectedCommissionTier, Mode=TwoWay, 
                                         UpdateSourceTrigger=PropertyChanged}" 
                  DisplayMember="CommissionValue"
                  ItemStringFormat="{}{0}%">

答案 2 :(得分:0)

您可以按如下方式修改ComboBox的ItemTemplate:

<ComboBox x:Name="cmbCommissionTier" 
          ItemsSource="{Binding ListCommissionTier, Mode=TwoWay}" 
          SelectedItem="{Binding SelectedCommissionTier, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" 
          >
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding Path=CommissionValue}"/>
                <TextBlock Text="%"/>
            </StackPanel>
        </DataTemplate>
    </ComboBox.ItemTemplate>
</ComboBox>