Так что, как и большинство, я все еще новичок и перемещаюсь по всем вещам c # и Xamarin.Forms, но это происходит исключительно медленно.Используя XamarinForms и плагин XamForms.Controls.Calendar, я пытаюсь создать календарь, который получает список дат и событий, которые произошли, и помещает небольшой цветной код внизу.Я рассмотрел весь исходный код и темы по этому, что я мог найти, и я реорганизовал его и построил ВЕРСИЮ кода ниже, который делает то, что я хочу, но это уродливо ... Я хочу сделать его более пригодным для повторного использования и более MVVMчем пример, который они использовали ранее, и что я сделал.По сути, мой план состоит в том, чтобы привязать цвета к активности на основе значения bool (должно быть видно в коде).Итак, проблема в том, что я на самом деле не знаю, куда идти и что делать, но вот, что я думаю, должно произойти.Пожалуйста, прости меня, если это простой вопрос, я просто не вижу его.
XamlPage
<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:controls="clr-namespace:XamForms.Controls;assembly=XamForms.Controls.Calendar"
x:Class="MyApp.View.LogPageViews.LogPage"
ControlTemplate="{StaticResource MainPageTemplate}">
<ContentPage.Content>
<ScrollView>
<StackLayout>
<controls:Calendar x:Name="calendar Padding="10,0,10,0" SelectedBorderWidth="4" DisabledBorderColor="Black" ShowNumberOfWeek="false" StartDay="Monday TitleRightArrowTextColor="Blue" TitleLabelTextColor="Purple" TitleLeftArrowTextColor="Blue" WeekdaysFontSize="12" SelectedDate="{Binding Date}" SpecialDates="{Binding Workout}" DateCommand="{Binding DateChosen}" >
</controls:Calendar>
</StackLayout>
</ScrollView>
</ContentPage.Content>
</ContentPage>
Я получаю свою ошибку в коде со всем, что я пробовал ... что, возможно, несколько неправильно ... и я даже не знаю, еслиэто хороший кодМоя текущая ошибка: Код серьезности Описание Состояние подавления строки файла проекта CS1503 Аргумент 1: невозможно преобразовать из «MyApp.ViewModel.CalendarActivityVM» в «XamForms.Controls.SpecialDate»
namespace MyApp.View.LogPageViews
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class LogPage : ContentPage
{
public LogPage ()
{
InitializeComponent ();
var Dates = new List<SpecialDate>();
NavigationPage.SetHasNavigationBar(this, false);
DateTime testdate = new DateTime(2018, 06, 26);
//This is where I am getting the errors when I try to do anything like this. Getting errors like "Cannot convert from" and "Cannot use like a method"
//I did have code here that worked, but refactored it out and got stuck
calendar.SpecialDates.Add(new CalendarActivityVM(testdate, true, true, true, true));
calendar.SelectedDate = (DateTime.Now);
}
}
}
Мой календарь ActivityVM (у меня естьПонятия не имею, если это правильно ... Это то, где я учусь и думаю, что это правильно)
namespace MyApp.ViewModel
{
public class CalendarActivityVM
{
public DateTime Datetime { get; set; }
public bool A { get; set; }
public bool B { get; set; }
public bool C { get; set; }
public bool D { get; set; }
public CalendarActivityVM(DateTime datetime, bool a, bool b, bool c, bool d)
{
Datetime = datetime;
A = a;
B = b;
C = c;
D = d;
var AColor = new Color();
var BColor = new Color();
var CColor = new Color();
var DColor = new Color();
if (A == true) { AColor = Color.Red; } else { AColor = Color.Transparent; };
if (B == true) { BColor = Color.Yellow; } else { BColor = Color.Transparent; };
if (C == true) { CColor = Color.Green; } else { CColor = Color.Transparent; };
if (D == true) { DColor = Color.Blue; } else { DColor = Color.Transparent; };
var white_row = new Pattern { WidthPercent = .1275f, HightPercent = 0.75f, Color = Color.Transparent };
var white_col = new Pattern { WidthPercent = 0.04f, HightPercent = 1f, Color = Color.Transparent };
var aPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = AColor };
var bPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = BColor };
var cPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = CColor };
var dPattern = new Pattern { WidthPercent = 0.22f, HightPercent = 0.22f, Color = DColor };
var activity = new BackgroundPattern(7)
{
Pattern = new List<Pattern>
{
white_row, white_row, white_row, white_row, white_row, white_row, white_row,
aPattern, white_col, bPattern, white_col, cPattern, white_col, dPattern
}
};
}
}
}
нормальный "SpecialDate" выглядит так в соответствии с примером ... вот почему япытаюсь провести рефакторинг:
calendar.SpecialDates = new List<SpecialDate>{
new SpecialDate(DateTime.Now.AddDays(3))
{
BackgroundColor = Color.White,
TextColor = Color.Black,
Selectable = true,
BackgroundPattern = new BackgroundPattern(7)
{
Pattern = new List<Pattern>
{
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Red, Text = "X", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Gold, Text = "Y", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Green, Text = "Z", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Purple,Text = "Q", TextColor=Color.White, TextSize=11, TextAlign=TextAlign.Middle},
white_row,white_row,white_row,white_row,white_row,white_row,white_row,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Blue},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Chocolate},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Cyan},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Fuchsia},
white_row,white_row,white_row,white_row,white_row,white_row,white_row,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Crimson},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Aquamarine},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.OrangeRed},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.DarkOrchid},
white_row,white_row,white_row,white_row,white_row,white_row,white_row,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Black},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.DeepSkyBlue},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.DarkGoldenrod},
white_col,
new Pattern{ WidthPercent = 0.22f, HightPercent = 0.22f, Color = Color.Firebrick},
}
}
}
Я ценю ваше время, и любая помощь очень ценится.