我想填充一列作为组合框的数据网格,但我需要当绑定到组合框的集合为空时列变为文本框列。我已经定义了如下列:根据源更改列样式
Binding binding = new Binding(“DataContext.Prices”); binding.RelativeSource = new RelativeSource(RelativeSurceMode.FindAncestor,typeof(UserControl),1);
DataGridComboBoxColumn productPrices = new DataGridComboBoxColumn()
{
ElementSyle = new Style
{
TargetType = typeof(ComboBox),
Setters =
{
new Setter
{
Property=ComboBox.ItemsSourceProperty,
Value= binding
}
}
},
EditingElementSyle = new Style
{
TargetType = typeof(ComboBox),
Setters =
{
new Setter
{
Property=ComboBox.ItemsSourceProperty,
Value= binding
}
}
},
DisplayMemberPath = new Binding("Price");
SelectedValuePath = new Bindnt("Price");
};
myDataGrid.Columns.Add(productPrices);
myDataGrid.Columns.Add(new DataGridTextColumn(){ Header="Name", Binding=new Binding("Name")});
我定义myDataGrid:
<DataGrid Name="myDataGrid" ItemsSource="{Binding Products}" />
在我的视图模型我创建了一个
var products = new List<Product>
{
new Product
{
Name="Prod 1",
Price="12.5"
}
}
var prices = new List<PriceL>
{
new PriceL
{
Price="12.5"
},
new PriceL
{
Price="10"
}
}
ICollectionView Products = CollectionViewSource.GetDefaultView(products);
ICollectionView Prices = CollectionViewSource.GetDefaultView(prices);
我需要的是,当“价格”是空列成为一个文本框,我的工作与MVVM和我尝试与elementStyle,但我不能看到Combobox中的任何事件,让我验证它的数据源。任何机构能帮助我吗?
好的,谢谢我要去搜索它。但是你知道与Visual Studio合作的任何信息来源吗?我不在混合 – Nandhi
下载试用版并使其运行。它只会将代码添加到Xaml中,而不会让您无法购买该产品。但是(恕我直言)真正成为一名熟悉Blend的Xaml开发人员不会损害您的职业生涯,如果您发现它是一种使用工具,请让管理层购买它。 – OmegaMan