Добрый день всем. У меня есть продукты, которые имеют одинаковые названия, но имеют разную цену, и когда пользователь делает выбор, он должен видеть в ComboBox строку «ProductName +» «+ Price», но когда выбор завершен, он должен видеть только «Название продукта». Я перепробовал все, что знаю, но ничего не смог сделать. Пожалуйста, помогите мне кто-нибудь.
<Page
x:Class="CompaniesAndProducts.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:CompaniesAndProducts"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:MSControls="using:Microsoft.Toolkit.Uwp.UI.Controls"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.3*"></ColumnDefinition>
<ColumnDefinition Width="0.7*"></ColumnDefinition>
<ColumnDefinition Width="0.3*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<MSControls:DataGrid Grid.Column="1"
ItemsSource="{x:Bind Companies}"
AutoGenerateColumns="False"
ScrollViewer.HorizontalScrollMode="Enabled"
RowHeight="60">
<MSControls:DataGrid.Columns>
<MSControls:DataGridTextColumn Header="Company Name"
Binding="{Binding Name}"/>
<MSControls:DataGridComboBoxColumn Header="Product"
Binding="{Binding CompanyId}"
ItemsSource="{x:Bind Products}"
DisplayMemberPath="NameAndPrice"/>
</MSControls:DataGrid.Columns>
</MSControls:DataGrid>
</Grid>
</Page>
namespace CompaniesAndProducts
{
public class Company
{
public int CompanyId { get; set; }
public string Name { get; set; }
}
public class Product
{
public int ProductId { get; set; }
public int CompanyId { get; set; }
public string Name { get; set; }
public decimal Price { get; set; }
public string NameAndPrice
{
get
{
return Name + " " + Price.ToString();
}
}
}
public sealed partial class MainPage : Page
{
public List<Company> Companies { get; set; }
public List<Product> Products { get; set; }
public MainPage()
{
this.InitializeComponent();
Companies = new List<Company>()
{
new Company(){CompanyId = 1, Name="GoodCompany"},
};
Products = new List<Product>()
{
new Product(){ProductId = 1, CompanyId = 1, Name="Yellow Ice Cream", Price = 16},
new Product(){ProductId = 2, CompanyId = 1, Name="Yellow Ice Cream", Price = 21}
};
}
}
}