第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

如何在 Xamarin Forms 中的按鈕上創(chuàng)建網(wǎng)格

如何在 Xamarin Forms 中的按鈕上創(chuàng)建網(wǎng)格

C#
寶慕林4294392 2022-01-09 16:36:54
所以我需要?jiǎng)?chuàng)建一個(gè)自定義按鈕,在我必須創(chuàng)建的網(wǎng)格上,在這個(gè)網(wǎng)格上我需要?jiǎng)?chuàng)建幾個(gè)帶有特定信息的標(biāo)簽。這是我將孩子添加到按鈕的代碼    private void HighlightTodayDay()    {        Label label1 = new Label()        {            BackgroundColor = Color.DarkRed,            Text = "lbl1"        };        Label label2 = new Label()        {            BackgroundColor = Color.Gold,            Text = "lbl2"        };        if ((DateTime.Today.Year == actualVisibleMonth.Year) && (DateTime.Today.Month == actualVisibleMonth.Month))        {            foreach (var child in Children.Reverse())            {                if (child.ClassId.ToString() == ("actualDayButtonID" + DateTime.Today.Day.ToString()) && child.IsEnabled == true)                {                    DayButton todayDayButton = dayButtonsList[DateTime.Today.Day + shiftOfFirstDay];                    todayDayButton.TextColor = Color.FromHex("#0f0");                    //upto this line everything is working as it should                    todayDayButton.insideGrid.Children.Add(label1, 0, 0);  //do nothing                    todayDayButton.insideGrid.Children.Add(label2, 0, 1); //do nothing                    return;                }            }        }    }這是“自定義”按鈕的代碼    class DayButton : Button{    public string EventDate;    public string EventStartTime;    public string EventEndTime;    public string EventShift;    public string EventName;    public string EventDescription;    public Grid insideGrid;    public DayButton()    {        insideGrid = new Grid();        insideGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });        insideGrid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(3, GridUnitType.Star) });        insideGrid.Parent = this;    }}
查看完整描述

2 回答

?
素胚勾勒不出你

TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊

我決定關(guān)閉按鈕并將其更改為堆棧布局(惡心?。?,并為此堆棧布局添加帶有事件的新標(biāo)簽!soo 代碼如下所示:


public partial class Calendar : Grid

{...


    public delegate void OnDayClickedDelegate(DateTime dateOfClickedDay);

    public event OnDayClickedDelegate OnDayClicked;

...

        private void DayClick(DateTime clickedDate)

    {

        OnDayClicked(clickedDate);

    }

...

private void SomeVoid()

{...

 DayLayout eventInDay = dayLayoutList[dayID];

                var eventLabel = new Label

                {

                    BackgroundColor = color,

                    Text = name.ToUpper(),

                    FontSize = Device.GetNamedSize(NamedSize.Small, typeof(Label)),

                    FontAttributes = FontAttributes.Bold

                };

                eventInDay.Children.Add(eventLabel);

...}

}


和日視圖


        private class DayLayout : StackLayout

    {

        public delegate void OnClickedDelegate(DateTime dateOfClickedDay);

        public event OnClickedDelegate OnClicked;


        public Label DayNumber;


        public DayLayout(DateTime day)

        {

            GestureRecognizers.Add

            (

                new TapGestureRecognizer

                {

                    Command = new Command(() => OnClicked(day))

                }

            );


            var dayNumber = new Label

            {

                HorizontalTextAlignment = TextAlignment.End,

                VerticalTextAlignment = TextAlignment.Start,

                Text = day.ToString("dd"),

                FontSize = Device.GetNamedSize(NamedSize.Micro, typeof(Label)),

                FontAttributes = FontAttributes.Bold

            };


            DayNumber = dayNumber;

            this.Children.Add(DayNumber);

        }

    }


查看完整回答
反對(duì) 回復(fù) 2022-01-09
?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊

您可以將 GestureRecognizer 添加到 Grid 中,然后綁定點(diǎn)擊事件。


Ex 按鈕代碼(現(xiàn)在是 ContentView):


            class DayButton : ContentView

        {

            public string EventDate;

            public string EventStartTime;

            public string EventEndTime;

            public string EventShift;

            public string EventName;

            public string EventDescription;

            public Grid insideGrid;


            public event EventHandler Clicked;


            private TapGestureRecognizer _buttonTap;

            private Lable _ButtonText;


            public DayButton()

            {

                _ButtonText = new Lable 

                { 

                      Text = EventName

                }


                insideGrid = new Grid

            {

                VerticalOptions = LayoutOptions.FillAndExpand,

                HorizontalOptions = LayoutOptions.FillAndExpand,

                RowSpacing = 0,


                RowDefinitions =

                {

                    new RowDefinition {Height = GridLength.Auto} //0

                },

                ColumnDefinitions =

                {

                    new ColumnDefinition {Width = GridLength.Star} //0

                }

            };


               //Add your elements to the grid

               insideGrid.Children.Add(_ButtonText, 0, 1, 0, 1)


               //Set the grid as the content of this view

               Content = insideGrid;




                _buttonTap = new TapGestureRecognizer();

                this.GestureRecognizers.Add(_buttonTap);

                _buttonTap.Tapped += ButtonClicked;

            }

        }


            private async void ButtonClicked(object sender, EventArgs e)

            {

                if (this.IsEnabled)

                {

                    Clicked?.Invoke(this, e);

                }


            }

然后,您可以在實(shí)現(xiàn)按鈕的位置綁定“Clicked”事件。


private DayButton _btn1 = new DayButton(){ EventName = "FooBaar"};


protected override void OnAppearing()

{

   _btn1.Clicked += OnDayBtnClicked;

   base.OnAppearing();

}


protected override void OnDisappearing()

{

   _btn1.Clicked -= OnDayBtnClicked;

   base.OnDisappearing();

}


private void OnDayBtnClicked(object sender, EventArgs e)

{

     //What to do when a button is clicked

}


查看完整回答
反對(duì) 回復(fù) 2022-01-09
  • 2 回答
  • 0 關(guān)注
  • 160 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)