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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

選中數(shù)組中的復(fù)選框時更新標(biāo)簽

選中數(shù)組中的復(fù)選框時更新標(biāo)簽

C#
繁花如伊 2022-12-24 10:55:39
我正在嘗試實現(xiàn)一種快速排序算法來對浮點數(shù)組進行排序。每當(dāng)我引用數(shù)組中的索引時,我都會收到此錯誤:無法將類型“float”隱式轉(zhuǎn)換為“int”。存在顯式轉(zhuǎn)換(您是否缺少轉(zhuǎn)換)?這是算法:class Quicksort{    public static void Sort(float[] numbers, int left, int right)    {        float i = Convert.ToSingle(left);        float j = Convert.ToSingle(right);        var pivot = numbers[(left + right) / 2];        while (i <= j)        {            while (numbers[i] < pivot) //ERROR HERE                i++;            while (numbers[j] > pivot) //ERROR HERE                j--;            if (i <= j)            {                float tmp = numbers[i]; //ERROR HERE                numbers[i] = numbers[j]; //ERROR HERE                numbers[j] = tmp; //ERROR HERE                i++;                j--;            }        }        if (left < j)            Sort(numbers, left, j);        if (i < right)            Sort(numbers, i, right);    }}numbers[i]每當(dāng)我使用或時出現(xiàn)轉(zhuǎn)換錯誤numbers[j]我將如何解決這個問題?
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻1784條經(jīng)驗 獲得超7個贊

我剛剛為你的場景寫了一個例子,看看我認為它會有所幫助


Xaml


  <StackPanel Grid.Row="0" Grid.Column="1">

        <ItemsControl ItemsSource="{Binding Path=CBItems}">

            <ItemsControl.ItemsPanel>

                <ItemsPanelTemplate>

                    <StackPanel Orientation="Horizontal"/>

                </ItemsPanelTemplate>

            </ItemsControl.ItemsPanel>

            <ItemsControl.ItemTemplate>

                <DataTemplate>

                    <CheckBox IsChecked="{Binding Path=CheckBoxChecked, Mode=TwoWay}" Command="{Binding Path=DataContext.CheckBoxChanged, RelativeSource={RelativeSource AncestorType=ItemsControl}}"/>

                </DataTemplate>

            </ItemsControl.ItemTemplate>

        </ItemsControl>

        <Label Content="{Binding LabelContent}"></Label>

    </StackPanel>

Ctro(設(shè)置數(shù)據(jù)上下文)


 public partial class MainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

            MainWindowVM DC = new MainWindowVM();

            DC.Init();

            this.DataContext = DC;

        }

    }

繼電器命令和模型類


 class MainWindowVM : INotifyPropertyChanged

    {

        public MainWindowVM()

        {


            CheckBoxChanged = new RelayCommand(CheckBoxChangedMethod);


        }


        private string labelContent="Not Yet Checked";


        public string LabelContent

        {

            get { return labelContent; }

            set { labelContent = value; OnPropertyChanged(new PropertyChangedEventArgs("LabelContent")); }

        }



        public void Init()

        {

            try

            {

                CBItems = new ObservableCollection<ex>();

                for (int i = 985; i <= 1030; i++)

                    CBItems.Add(new ex { CheckBoxChecked = true });

            }

            catch (Exception ex)

            {


            }

        }


        public ICommand CheckBoxChanged { get; set; }




        private ObservableCollection<ex> _CBItems;

        public ObservableCollection<ex> CBItems

        {

            get { return _CBItems; }

            set

            {

                _CBItems = value;

                OnPropertyChanged(new PropertyChangedEventArgs("CBItems"));

            }

        }


        public event PropertyChangedEventHandler PropertyChanged;

        public void OnPropertyChanged(PropertyChangedEventArgs e)

        {

            if (PropertyChanged != null)

            {

                PropertyChanged(this, e);

            }

        }



        public void CheckBoxChangedMethod(object obj)

        {

            LabelContent = "You have Clicked the checkbox";

        }


    }


    public class RelayCommand : ICommand

    {

        private Action<object> execute;

        private Func<object, bool> canExecute;


        public event EventHandler CanExecuteChanged

        {

            add

            {

                CommandManager.RequerySuggested += value;


            }

            remove { CommandManager.RequerySuggested -= value; }

        }


        public RelayCommand(Action<object> execute, Func<object, bool> canExecute = null)

        {

            this.execute = execute;

            this.canExecute = canExecute;

        }



        public bool CanExecute(object parameter)

        {

            //return this.canExecute == null || this.canExecute(parameter);

            return true;

        }


        public void Execute(object parameter)

        {

            this.execute(parameter);

        }


        public RelayCommand(Action<object> execute)

        {

            this.execute = execute;


        }



    }


    public class ex

    {

        private bool _checkBoxChecked;


        public bool CheckBoxChecked

        {

            get { return _checkBoxChecked; }

            set { _checkBoxChecked = value; }

        }


    }



查看完整回答
反對 回復(fù) 2022-12-24
  • 1 回答
  • 0 關(guān)注
  • 80 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

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

公眾號

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