【发布时间】:2016-06-30 11:50:44
【问题描述】:
我不知道这是否可能,但我正在尝试从我的 XAML 文件中访问二维数组的元素。 首先,有可能吗?
我正在自己制作一个 CustomCalendar(它适用于 WriteLine 输出)。我现在正在尝试制作图形。
有一部分是C#部分:
public partial class Planning : ContentPage
{
public class DayCase
{
public string Day { get; set; }
public Color BackgroundColor { get; set; }
public Color BorderColor { get; set; }
public Color TextColor { get; set; }
}
public DayCase[][] Calendar; // It's the Grid in the Data way // Imagine it as a Grid
DateTime today;
private int _month;
public int Month[...]
public int Year;
private void createCalendar()
{
Calendar = new DayCase[6][]
{
new DayCase[7] { new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase()},
new DayCase[7] { new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase()},
new DayCase[7] { new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase()},
new DayCase[7] { new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase()},
new DayCase[7] { new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase()},
new DayCase[7] { new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase(), new DayCase()}
};
today = DateTime.Now;
_month = today.Month;
Year = today.Year;
}
private void initCalendar()[...]
// Here is an example to access data
public Color GetDayBackgroundColor(string index)
{
return (Calendar[Convert.ToInt32(index[0])][Convert.ToInt32(index[1])].BackgroundColor);
}
public Color GetDayBorderColor(string index)[...]
public Color GetDayTextColor(string index)[...]
public string GetDayNumber(string index)[...]
}
现在,我想通过我的 XAML 访问此 GridData、数组等的元素。GetDayBackgroundColor() 函数中的示例。
XAML部分:
<!-- Grid Planning part -->
<AbsoluteLayout BackgroundColor="White"
AbsoluteLayout.LayoutBounds="0.5, 0.71, 1, 0.79"
AbsoluteLayout.LayoutFlags="All">
<Grid BackgroundColor="Transparent"
AbsoluteLayout.LayoutBounds="0.5,0.95,0.9,0.7"
AbsoluteLayout.LayoutFlags="All">
<Grid.RowDefinitions>
<RowDefinition Height="5*"/>
<RowDefinition Height="15*"/>
...
<RowDefinition Height="5*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="14*"/>
...
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<!-- Here is the interesting part -->
<AbsoluteLayout Grid.Row="1" Grid.Column="1" BackgroundColor="Black">
<Label Text="{Binding GetDayNumber {00}}" TextColor="White" BackgroundColor="Transparent" HorizontalTextAlignment="Center" VerticalTextAlignment="Center"
AbsoluteLayout.LayoutBounds="0.5,0.5,1,1"
AbsoluteLayout.LayoutFlags="All"/>
</AbsoluteLayout>
</Grid>
</AbsoluteLayout>
它不起作用..我也尝试Text="{Binding Path=Calendar[y][x].Day}"(其中 x&y 是二维数组中的位置)但没有成功..
有人知道我该如何处理吗?
提前致谢!
【问题讨论】:
标签: xaml multidimensional-array grid