3
我得到了一個WPF MVVM應用程序,其中包含一個包含GridView的ListView。
使用助手類我創建了GridViewColumn,它很好地工作。以編程方式將屬性綁定到GridViewColumn.Width
我的問題:我想twoway綁定的寬度,所以我可以讀回寬度的變化。
代碼現在創建GridViewColumn看起來是這樣的:
private static GridViewColumn CreateColumn(GridView gridView, object columnSource)
{
GridViewColumn column = new GridViewColumn();
String headerTextMember = GetHeaderTextMember(gridView);
String displayMemberMember = GetDisplayMemberMember(gridView);
String widthMember = GetWidthMember(gridView);
// set header
column.Header = GetPropertyValue(columnSource, headerTextMember);
// set display binding
String propertyName = GetPropertyValue(columnSource, displayMemberMember) as String;
column.DisplayMemberBinding = new Binding(propertyName);
// bind with - but how?
//Binding widthBinding = new Binding(widthMember);
//widthBinding.Source = columnSource;
//widthBinding.Mode = BindingMode.TwoWay;
//gridView.SetBinding(GridViewColumn.WidthProperty, widthBinding); <- gridView got no SetBinding :(
}
return column;
}
任何人都得到了一些指針我,我怎麼可能能夠寬度綁定?
GridView控件不包含方法SetBinding,我在哪裏有找這個? – Sam 2010-07-19 12:01:37
它不在GridView中,它在BindingOperations中,如答案中所述... – 2010-07-19 12:08:52
@Sam:是的!由於GridViewColumn類(不是GridView)沒有SetBinding方法,綁定必須以這種方式完成。檢查我的編輯代碼。 – Amsakanna 2010-07-19 12:29:58