2
可能かどうかわかりませんが、XAMLファイルから二次元配列の要素にアクセスしようとしています。 まず、可能ですか?Xamarinフォーム - 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から、私はGetDayBackgroundColor()
機能でこのGridDataの要素は、Arrayなどの例にアクセスしたいと思います。
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>
それは.. ..私も(X & yは、二重次元配列内の位置です)Text="{Binding Path=Calendar[y][x].Day}"
が、成功せずにしようと動作しません
誰も私はそれを処理する方法を知っていますか?
ありがとうございます!
モード「TwoWay」を試す –