在代碼中,我將列添加到listview成功。但我想添加綁定到列而不是添加到列表視圖。拳頭是xaml中的工作代碼。後面的wpf綁定代碼
<GridViewColumn x:Name="colName" Header="Name" Width="130">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Values, Converter={StaticResource LoadProfileConverter},ConverterParameter=active_total}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
代碼後面:
GridViewColumn column = new GridViewColumn();
column.Header = "Header";
column.Width = 130;
FrameworkElementFactory controlFactory = new FrameworkElementFactory(typeof(TextBlock));
var itemsBinding = new System.Windows.Data.Binding("Values")
{
Converter = new LoadProfileConverter(),
ConverterParameter = "active_total",
};
controlFactory.SetBinding(TextBox.TextProperty, itemsBinding);
DataTemplate template = new DataTemplate();
template.VisualTree = controlFactory;
column.CellTemplate = template;
LoadProfileGrid.Columns.Add(column);
請在發佈之前重新閱讀。 – franssu 2012-08-14 11:40:11
http://msdn.microsoft.com/en-us/library/ms742863.aspx如何:在代碼中創建綁定 – ShadeOfGrey 2012-08-14 11:42:46
@ShadeOfGrey但這裏沒有關於ConverterParameter(( – 2012-08-14 12:17:32