我有一個自定義頁面和一個自定義控件。在XAML中填充泛型列表
public class TilesPage : ContentPage
{
public ObservableCollection<Tile> Tiles
{
get;
set;
}
}
public class Tile : Frame
{
public static readonly BindableProperty TitleProperty = BindableProperty.Create(nameof(Title), typeof(string), typeof(Tile), null);
public Tile()
{
HasShadow = false;
}
public string Title
{
get
{
return (string)GetValue(TitleProperty);
}
set
{
SetValue(TitleProperty, value);
}
}
}
所以我的頁面有一個瓷磚的集合,即框架。 現在我想通過XAML填充集合。
我的XAML語法時纔是這樣的:
<?xml version="1.0" encoding="utf-8" ?>
<CPages:TilesPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MyNamespace.AboutPage"
xmlns:CControls="clr-namespace:MyNamespace;assembly=MyAssembly"
xmlns:CPages="clr-namespace:MyNamespace;assembly=MyAssembly"
>
<CPages:TilesPage.Tiles>
<CControls:Tile Title="Test">
<CControls:Tile.Content>
<Label>In Tile</Label>
</CControls:Tile.Content>
</CControls:Tile>
</CPages:TilesPage.Tiles>
</CPages:TilesPage>
但集合保持爲空。 XAML不會觸及它。
那麼我的語法有什麼問題?
嘗試使用**依賴屬性**。 –