8,736
社区成员
发帖
与我相关
我的任务
分享
<data:DataGrid x:Name="dataGrid" AutoGenerateColumns="False">
<data:DataGrid.Columns>
<data:DataGridTemplateColumn Header="City" SortMemberPath="CityInfo.CityName">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding CityInfo.CityName}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding CityList, Source={StaticResource cityProvider}}"
SelectedItem="{Binding CityInfo, Mode=TwoWay}"
DisplayMemberPath="CityName"
src:ComboBoxService.ForceOpen="true"
/>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>
</data:DataGrid.Columns>
</data:DataGrid>
<data:DataGrid x:Name="dataGrid" AutoGenerateColumns="False">
<data:DataGrid.Columns>
</data:DataGrid.Columns>
</data:DataGrid>
<data:DataGridTemplateColumn Header="City" SortMemberPath="CityInfo.CityName">
<data:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding CityInfo.CityName}" />
</DataTemplate>
</data:DataGridTemplateColumn.CellTemplate>
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding CityList, Source={StaticResource cityProvider}}"
SelectedItem="{Binding CityInfo, Mode=TwoWay}"
DisplayMemberPath="CityName"
src:ComboBoxService.ForceOpen="true"
/>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
</data:DataGridTemplateColumn>
textColumn.CellTemplate = this.CreatDataTemplate(typeof(TextBlock), bindDataName, bindColorName);
<data:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding CityList, Source={StaticResource cityProvider}}"
SelectedItem="{Binding CityInfo, Mode=TwoWay}"
DisplayMemberPath="CityName"
src:ComboBoxService.ForceOpen="true"
/>
</DataTemplate>
</data:DataGridTemplateColumn.CellEditingTemplate>
public DataTemplate CreatDataTemplate(Type type, string bindDataName, string bindColorName)
{
StringBuilder sbTemp = new StringBuilder();
sbTemp.Append("<DataTemplate ");
sbTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ");
sbTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ");
sbTemp.Append("xmlns:local='clr-namespace:PerfDashboard.BuildCompare;assembly=YourAssembly'>");
sbTemp.Append("<Grid>");
sbTemp.Append("<Grid.Resources>");
sbTemp.Append("<local:FontColorConverter x:Key='colorFormat'/>");
sbTemp.Append("</Grid.Resources>");
sbTemp.Append("<TextBlock Foreground=\"{Binding " + bindColorName + ", Converter={StaticResource colorFormat}}\" ");
sbTemp.Append("Text=\"{Binding " + bindDataName + "}\" ");
sbTemp.Append("HorizontalAlignment=\"Center\" VerticalAlignment=\"Center\"/>");
sbTemp.Append("</Grid>");
sbTemp.Append("</DataTemplate>");
return (DataTemplate)XamlReader.Load(sbTemp.ToString());
}
DataGridTemplateColumn textColumn = new DataGridTemplateColumn();
textColumn.Header = "Test1";
string bindDataName = string.Format("TestCaseValueList[{0}]", i);
string bindColorName = string.Format("TestCaseValueList[{0}].IsPassed", i);
textColumn.CellTemplate = this.CreatDataTemplate(typeof(TextBlock), bindDataName, bindColorName);