我試圖動態地填充自動填充的值。我得到一個SearchResult元組列表,其中每個元組的第一個字符串是KEY,字符串列表是每列需要顯示的顯示文本。假設是任何SearchResult列表中的所有行都將包含顯示文本列表中相同數量的項目。我真的希望能夠綁定到按順序顯示文本列表的值...F#Silverlight:使用PropertyPath或其他方法來按順序綁定列
一個簡單的例子將採取的數據是這樣的:
[
("MSFT.OQ", ["MSFT.OQ"; "Microsoft"; "Nasdaq"]) ;
("GOOG.OQ", ["GOOG.OQ"; "Google"; "Nasdaq"]);
]
,並顯示:
MSFT.OQ Microsoft Nasdaq
GOOG.OQ Google Nasdaq
但我看到的是這樣的:
["MSFT.OQ"; "Microsoft"; "Nasdaq"] ["MSFT.OQ"; "Microsoft"; "Nasdaq"] ["MSFT.OQ"; "Microsoft"; "Nasdaq"]
["GOOG.OQ"; "Google"; "Nasdaq"] ["GOOG.OQ"; "Google"; "Nasdaq"] ["GOOG.OQ"; "Google"; "Nasdaq"]
完整列表將在每列結束了,所以我認爲我的裝訂已關閉。
我的示例代碼(試圖從一個更復雜的模型簡化):令人驚訝
type SearchResult = (string * string list)
type Template() as this =
inherit Page
[<DefaultValue>]
val mutable acbTickerSearch : AutoCompleteBox
do
this.acbTickerSearch = this ? acbTickerSearch
this.display Some(this.getSampleResults())
member private this.getSampleResults() =
[
("MSFT.OQ", ["MSFT.OQ"; "Microsoft"; "Nasdaq"]) ;
("GOOG.OQ", ["GOOG.OQ"; "Google"; "Nasdaq"]);
("IBM", ["IBM"; "International Business Machines"; "NYSE"]);
("AKAM.OQ", ["AKAM.OQ"; "Akamai"; "Nasdaq"]);
]
member this.display (results: SearchResult list option) =
let build(result: SearchResult) =
// if we haven't built the bindings yet lets do so
if this.tickerSearchDataGrid = null then
// create a grid
this.tickerSearchDataGrid <- new DataGrid()
this.tickerSearchDataGrid.AutoGenerateColumns <- false
let addColumn i (item: string) =
let col = new DataGridTextColumn()
let binding = System.Windows.Data.Binding()
// LOOK HERE: attempting to bind to an indexer... not working so well,,
binding.Path <- PropertyPath([i])
col.Binding <- binding
this.tickerSearchDataGrid.Columns.Add(col)
i + 1
result
// the second portion of the tuple, is a list that
// needs to be displayed, wach item in its own column
|> snd
// should probably be List.iteri
|> List.fold addColumn 0
// don't need this with List.iteri
|> ignore
let displayResults (resultLst: SearchResult list) =
// create a list of lists, throwing away the "key" portion of the tuple
// potentially a bug I need toget around...
let lst =
resultLst
|> List.map (fun (r: SearchResult) -> snd r)
// bind to the data source
this.tickerSearchDataGrid.ItemsSource <- lst
this.tickerSearchDataGrid.HeadersVisibility <- DataGridHeadersVisibility.None
this.acbTickerSearch.ItemsSource <- [this.tickerSearchDataGrid]
this.acbTickerSearch.IsDropDownOpen <- true
match results with
| None ->()
| Some r ->
// set the number of columns based on the results,
// assume all tuples will have an equal number of values,
// we only need the head to determine the columns then
build <| List.head r
// bind the results
displayResults r
謝謝...
(至少對我來說),這些返回相同的結果:
binding.Path <- PropertyPath([])
binding.Path <- PropertyPath("")
binding.Path <- PropertyPath([0].[0])
賺不了多少意義的,我...
不幸的是,它沒有奏效。我昨天早些時候閱讀了該頁面,並嘗試了類似的東西(我昨天沒有詳細查看您的帖子,因爲我正在跑火車趕上),但這也不起作用。它顯示了一個四分之一的小格子,大約四分之一的大小,裏面沒有文字。如果這個類有更好的文檔或源代碼(屬性路徑) - 那會很好 - 但它似乎不起作用,至少在F#中並且綁定到索引器以用於數據網格綁定。 – akaphenom 2010-12-08 14:13:13