簡體   English   中英

如何使用代碼創建 DataTemplate? [毛伊]

[英]How to create DataTemplate with code? [MAUI]

如何使用代碼創建 DataTemplate?

DataTemplate 沒有像 WPF 中那樣的 VisualTree 屬性。

文檔也無濟於事。

有一個 IDataTemplateController,但它不控制任何東西。 <ignorable>又出現了奇怪的 MAUI 時間</ignorable>。

在源代碼中找到它:創建視圖的函數有一個構造函數參數。

/// <Docs>
///   <param name="loadTemplate">A custom content generator to be called </param>
///   <summary>Creates and initializes a new instance of the <see cref="T:Microsoft.Maui.Controls.DataTemplate" /> class.</summary>
///   <remarks>To be added.</remarks>
/// </Docs>
public DataTemplate(Func<object> loadTemplate);
new DataTemplate(() => {
    var label = new Label();
    label.SetBinding(Label.TextProperty, new Binding("."));
    return label;
});

Binding 中當前存在一個錯誤,您必須指定“.”,一個修復被合並。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM