【问题标题】:How to show 1 value from 2 values in combobox xaml?如何在组合框 xaml 中显示 2 个值中的 1 个值?
【发布时间】:2014-07-03 14:06:27
【问题描述】:

您好,我有一个 ComboBox,显示 2 个值名称和代码,当我按下下拉菜单时我想要它 在 ComboBox 中显示 2 个值,但是当我从下拉列表中选择时,我想要代码 只返回组合框 然后在其他 TextBox 中返回名称。

<ComboBox ItemsSource="{Binding StoreList,Mode=TwoWay}" 
          VerticalAlignment="Center"
          Grid.Column="1"
          Name="ItemAutoComplete"
          SelectedItem="{Binding TransactionHeader.StorePerRow,Mode=TwoWay}"
          Margin="0,0,105,6"
          Grid.ColumnSpan="3"
          IsEnabled="{Binding TransactionHeader.inter, Mode=TwoWay }"
          SelectedValue="iserial"
          Grid.Row="2"
          Height="44">
  <ComboBox.ItemTemplate>
    <DataTemplate>
      <Grid>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
          <ColumnDefinition Width="*" />                         
        </Grid.ColumnDefinitions>
        <StackPanel>
          <TextBlock Text="{Binding ENAME}"></TextBlock>
          <TextBlock Text="{Binding code}"></TextBlock>
        </StackPanel>
      </Grid>
    </DataTemplate>
  </ComboBox.ItemTemplate>
</ComboBox>

我想在文本框中返回 ename

仅当我从列表中选择时才显示代码

【问题讨论】:

    标签: xaml combobox silverlight-5.0


    【解决方案1】:

    像这样将 TextBox 的 Text-Property 绑定到 ComboBox 的 SelectedItem 上

    <TextBox Text={Binding SelectedItem.ENAME, ElementName=ItemAutoComplete}/>
    

    这将显示在您的 ComboBox 中选择的 Item 的属性 ENAME 的值。

    【讨论】:

    • 谢谢它的工作,但我只想在组合框中返回代码任何想法
    • 只需删除在ComboBox 模板中显示enameTextBlock 然后...
    猜你喜欢
    • 2013-01-01
    • 1970-01-01
    • 2020-07-25
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 2020-10-18
    • 2012-11-26
    • 2021-08-16
    相关资源
    最近更新 更多