当前位置: 首页>>代码示例>>C#>>正文


C# List.FirstOrDefault方法代码示例

本文整理汇总了C#中System.Windows.Documents.List.FirstOrDefault方法的典型用法代码示例。如果您正苦于以下问题:C# List.FirstOrDefault方法的具体用法?C# List.FirstOrDefault怎么用?C# List.FirstOrDefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Documents.List的用法示例。


在下文中一共展示了List.FirstOrDefault方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddCommentButton_Click

 private void AddCommentButton_Click(object sender, RoutedEventArgs e)
 {
     var engine = new CommentEngine();
     try
     {
         List<RadioButton> buttons = new List<RadioButton>
     {
         g1,g2,g3,g4,g5,g6,g7,g8,g9,g10
     };
         var selected = buttons.FirstOrDefault(x => (bool)x.IsChecked);
         if (selected != null)
         {
             string text = "";
             var grade = Convert.ToInt32(selected.Name.Remove(0, 1));
             if (CommentText.Text != "Добавить комментарий..." && CommentText.Text != "")
             {
                 text = CommentText.Text;
             }
             //надо вытащить id работы и юзера
             int workId = 8;
             string userId = "mamaAmaCriminal";
             engine.AddComment(userId, workId, grade, text);
             this.Close();
         }
         else
         {
             MessageBox.Show("Вы не оценили работу!", "Оценка отсутствует");
         }
     }
     catch(Exception exc)
     {
         MessageBox.Show(exc.Message,"Возникла ошибка");
     }
 }
开发者ID:LebGrigori,项目名称:StudentWorksSearch,代码行数:34,代码来源:GradeWork.xaml.cs

示例2: LoadControlData

        public void LoadControlData(List<Mapping> mappingData)
        {
            btnNext.Visibility = System.Windows.Visibility.Hidden;
            if (mappingData != null)
            {
                if (mappingData.FirstOrDefault() != null)
                {
                    if (mappingData.FirstOrDefault().inputFilenames.FirstOrDefault() != null)
                    {
                        txtInputFile.Text = mappingData.FirstOrDefault().inputFilenames.FirstOrDefault();

                        inputfiles.inputFilenames.Add(mappingData.FirstOrDefault().inputFilenames.FirstOrDefault());
                        btnNext.Visibility = System.Windows.Visibility.Visible;
                    }
                }
            }
        }
开发者ID:kavamara,项目名称:CAMS_ETL,代码行数:17,代码来源:ucInputFiles.xaml.cs

示例3: Messages

        public Messages()
        {
            _messages = CMClient.Instance().LastDisplayContext.Messages;

            Message message = _messages.FirstOrDefault(item => item.Id == CMClient.Instance().LastDisplayContext.InitialMessageId);
            if(message != null)
            {
                _currentMessage = _messages.IndexOf(message);
            }

            DataContext = this;
            InitializeComponent();

            ShowMessage();
        }
开发者ID:clyngmobile,项目名称:wp,代码行数:15,代码来源:Messages.xaml.cs

示例4: Bind

        public void Bind(List<Track> musicItems)
        {
            var selectedItem = comboBox.SelectedValue as ComboBoxItem;
            items = musicItems.Select(t => new ComboBoxItem
            {
                NameWithSinger = t.GetNameWithSinger(),
                TimeString = t.GetTimeString(),
                Track = t
            }).ToList();

            comboBox.ItemsSource = items;

            if (selectedItem != null)
                comboBox.SelectedItem = items.FirstOrDefault(i => selectedItem.Track.Equals(i.Track));
        }
开发者ID:reflash,项目名称:VkMusic,代码行数:15,代码来源:MusicSelectControl.xaml.cs

示例5: Generate

		public DependencyObject[] Generate(HtmlNode node, IHtmlTextBlock textBlock)
		{
			var list = new List<Grid>();
			foreach (var child in node.Children.Where(c => c.Value == "li"))
			{
				var grid = new Grid();
				grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
				grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });

				var tb = new TextBlock();
				tb.Foreground = textBlock.Foreground;
				tb.FontSize = textBlock.FontSize;
				tb.FontFamily = textBlock.FontFamily;
				tb.Margin = new Thickness();
				tb.Text = "• ";

				grid.Children.Add(tb);
				Grid.SetColumn(tb, 0);

				var panel = new StackPanel();

				child.ToHtmlBlock();
				foreach (var c in child.GetLeaves(textBlock).OfType<UIElement>())
				{
					var frameworkElement = c as FrameworkElement;
					if (frameworkElement != null)
						frameworkElement.HorizontalAlignment = HorizontalAlignment.Stretch;
					panel.Children.Add(c);
				}

				grid.Children.Add(panel);
				Grid.SetColumn(panel, 1);

				list.Add(grid);
			}

			var first = list.FirstOrDefault();
			if (first != null)
				first.Margin = new Thickness(0, textBlock.ParagraphMargin, 0, 0);

			var last = list.LastOrDefault();
			if (last != null)
				last.Margin = new Thickness(0, 0, 0, textBlock.ParagraphMargin);

			return list.OfType<DependencyObject>().ToArray();
		}
开发者ID:fstn,项目名称:WindowsPhoneApps,代码行数:46,代码来源:UlGenerator.cs

示例6: PopulateLayoutRadioButtonsFromDisk

        /// <summary>
        /// Populates the layout radio buttons from disk.
        /// </summary>
        private void PopulateLayoutRadioButtonsFromDisk()
        {
            List<RadioButton> radioButtonList = new List<RadioButton>();
            var rockConfig = RockConfig.Load();
            List<string> filenameList = Directory.GetFiles( ".", "*.dplx" ).ToList();
            foreach ( var fileName in filenameList )
            {
                DplxFile dplxFile = new DplxFile( fileName );
                DocumentLayout documentLayout = new DocumentLayout( dplxFile );
                RadioButton radLayout = new RadioButton();
                if ( !string.IsNullOrWhiteSpace( documentLayout.Title ) )
                {
                    radLayout.Content = documentLayout.Title.Trim();
                }
                else
                {
                    radLayout.Content = fileName;
                }

                radLayout.Tag = fileName;
                radLayout.IsChecked = rockConfig.LayoutFile == fileName;
                radioButtonList.Add( radLayout );
            }

            if ( !radioButtonList.Any( a => a.IsChecked ?? false ) )
            {
                if ( radioButtonList.FirstOrDefault() != null )
                {
                    radioButtonList.First().IsChecked = true;
                }
            }

            lstLayouts.Items.Clear();
            foreach ( var item in radioButtonList.OrderBy( a => a.Content ) )
            {
                lstLayouts.Items.Add( item );
            }
        }
开发者ID:tcavaletto,项目名称:Rock-CentralAZ,代码行数:41,代码来源:SelectLayoutPage.xaml.cs

示例7: submit_Click

 private void submit_Click(object sender, RoutedEventArgs e)
 {
     if((code.Text == string.Empty) && (name.Text == string.Empty) && (brand.Text == string.Empty) && (price.Text == string.Empty) && (vat.Text == string.Empty) && (priceVat.Text == string.Empty) )
         System.Windows.MessageBox.Show("Musí byť vyplnený aspoň jeden údaj ");
     else {
         SearchEventArgs args = new SearchEventArgs();
         List<Interface.IOrder> ords = new List<Interface.IOrder>();
         List<Interface.IOrderItem> ordItems = Settings.Config.getOrderItems();
         if (!String.IsNullOrEmpty(code.Text.ToString()))
           ordItems =  ordItems.Where(x => x.code == code.Text.ToString()).ToList<Interface.IOrderItem>();
         if (!String.IsNullOrEmpty(brand.Text))
             ordItems = ordItems.Where(x => x.brand == brand.Text.ToString()).ToList<Interface.IOrderItem>();
         if (!String.IsNullOrEmpty(price.Text))
             ordItems = ordItems.Where(x => x.price.ToString() == price.Text.ToString()).ToList<Interface.IOrderItem>();
         if (!String.IsNullOrEmpty(vat.Text))
             ordItems = ordItems.Where(x => x.vat.ToString() == vat.Text.ToString()).ToList<Interface.IOrderItem>();
         if (!String.IsNullOrEmpty(priceVat.Text))
             ordItems = ordItems.Where(x => x.priceVat.ToString() == priceVat.Text.ToString()).ToList<Interface.IOrderItem>();
         foreach (var prod in ordItems)
         {
             MessageBox.Show(code.Text.ToString());
             Interface.IOrder ord = Settings.Config.getOrders().FirstOrDefault(x=> x.id == prod.orderId);
             if(ords.FirstOrDefault(x => x.id == ord.id) == null)
                 ords.Add(ord);
         }
         args.ords = ords;
         if (ords.Count == 0)
         {
             MessageBox.Show("Tento filter nenašiel žiadne výsledky.");
         }
         else
         {
             onSearched(args);
         }
     }
    
 }
开发者ID:Tabetha,项目名称:SchoolHellCoders,代码行数:37,代码来源:VyhladavanieTovarControl.xaml.cs

示例8: AttemptUseItem

        private bool AttemptUseItem(List<ACDItem> items)
        {
            var item = items.FirstOrDefault();
            if (item == null) return false;

            ZetaDia.Me.Inventory.UseItem(item.DynamicId);
            return true;
        }
开发者ID:herbfunk,项目名称:Funky,代码行数:8,代码来源:UseItemTag.cs

示例9: btnImportBorrowData_Click

        /// <summary>
        /// 导入借款单
        /// Creator:安凯航
        /// 日期:2011年5月30日
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void btnImportBorrowData_Click(object sender, RoutedEventArgs e)
        {
            //导入时间
            DateTime createTime = DateTime.Now;
            OpenFileDialog dialog = new OpenFileDialog()
            {
                Multiselect = false,
                Filter = "Excel 2007-2010 File(*.xlsx)|*.xlsx"
            };
            bool? userClickedOK = dialog.ShowDialog();

            // Process input if the user clicked OK.
            if (userClickedOK != true)
            {
                return;
            }
            try
            {

                //待保存数据列表
                List<OrderEntity> orders = new List<OrderEntity>();
                #region 读取Excel文件

                XLSXReader reader = new XLSXReader(dialog.File);
                List<string> subItems = reader.GetListSubItems();
                var maseters = reader.GetData(subItems[0]);
                var listm = maseters.ToDataSource();
                var details = reader.GetData(subItems[1]);
                var listd = details.ToDataSource();
                List<dynamic> masterList = new List<dynamic>();
                foreach (var item in listm)
                {
                    dynamic d = item;
                    masterList.Add(d);
                }
                //排除第一行信息
                masterList.Remove(masterList.First());

                List<dynamic> detailList = new List<dynamic>();
                foreach (var item in listd)
                {
                    dynamic d = item;
                    detailList.Add(d);
                }
                //排除第一行信息
                detailList.Remove(detailList.First());

                #endregion

                #region 添加主表
                List<T_FB_BORROWAPPLYMASTER> import = new List<T_FB_BORROWAPPLYMASTER>();
                foreach (var item in masterList)
                {
                    //构造OrderEntity数据
                    OrderEntity oe = new OrderEntity(typeof(T_FB_BORROWAPPLYMASTER));
                    orders.Add(oe);

                    T_FB_BORROWAPPLYMASTER t = oe.FBEntity.Entity as T_FB_BORROWAPPLYMASTER;
                    t.BORROWAPPLYMASTERID = Guid.NewGuid().ToString();
                    t.BORROWAPPLYMASTERCODE = item.单据号;
                    if (item.借款类型 == "普通借款")
                    {
                        t.REPAYTYPE = 1;
                    }
                    else if (item.借款类型 == "备用金借款")
                    {
                        t.REPAYTYPE = 2;
                    }
                    else if (item.借款类型 == "专项借款")
                    {
                        t.REPAYTYPE = 3;
                    }
                    else
                    {
                        continue;
                    }
                    t.REMARK = item.备注;
                    import.Add(t);
                }

                #endregion

                #region 添加子表

                foreach (var item in detailList)
                {
                    OrderEntity oe = orders.FirstOrDefault(oen =>
                    {
                        T_FB_BORROWAPPLYMASTER bm = oen.FBEntity.Entity as T_FB_BORROWAPPLYMASTER;
                        if (bm.BORROWAPPLYMASTERCODE == item.单据号)
                        {
                            return true;
                        }
//.........这里部分代码省略.........
开发者ID:JuRogn,项目名称:OA,代码行数:101,代码来源:CommonView.xaml.cs

示例10: LoadControlData

 public void LoadControlData(List<Mapping> mappingData)
 {
     btnNext.Visibility = System.Windows.Visibility.Hidden;
     if (mappingData != null)
     {
         if (mappingData.FirstOrDefault() != null)
         {
             txtInputFile.Text = mappingData.FirstOrDefault().OutputFolderPath;
             if (mappingData.FirstOrDefault().templateFilenames.FirstOrDefault() != null)
             {
                 if (mode == folderMode.templates)
                 {
                     txtInputFile.Text = mappingData.FirstOrDefault().TemplateFolder;
                     DisplayTemplates(mappingData.FirstOrDefault());
                 }
             }
         }
     }
     if (txtInputFile.Text != string.Empty) btnNext.Visibility = System.Windows.Visibility.Visible;
 }
开发者ID:kavamara,项目名称:CAMS_ETL,代码行数:20,代码来源:ucTemplates.xaml.cs

示例11: DownLoadDll

        /// <summary>
        /// 下载组件
        /// </summary>
        /// <param name="dllXElements"></param>
        private void DownLoadDll(List<string> dllXElements)
        {

            if (dllXElements.Count < 1)
            {
                if (UpdateDllCompleted != null)
                {
                    UpdateDllCompleted(this, null);
                }      
                return;
            }
            downloadDllName = dllXElements.FirstOrDefault();
            string path = @"http://" + SMT.SAAS.Main.CurrentContext.Common.HostIP + @"/ClientBin/" + downloadDllName + "?dt=" + DateTime.Now.Millisecond;
            DownloadDllClinet.OpenReadAsync(new Uri(path, UriKind.Absolute));
        }
开发者ID:fuhongliang,项目名称:oa,代码行数:19,代码来源:MainPagePartManager.cs

示例12: UpdateAll

        private void UpdateAll()
        {
            dgrid.Columns.Clear();
            if (!Episodes.Any()) return;


            var episodesSorted = Episodes.OrderBy(e => e, EpisodeComparer); //sort Episodes by season, episode
            var uploadsSorted = episodesSorted.SelectMany(e => e.Downloads.Select(d => d.Upload)).OrderBy(u=>u,UploadComparer).Distinct(); //get a unique collection of the Uploads, sorted by fav/nofav
     
            List<Header> headers = new List<Header>();
            _cells = new List<Cell>();
            int i = 0;

            //Idea: In the following Loop we create 1 Header instance for ALL Uploads (regardless of the season) which have the same String-Representation

            foreach (var upload in uploadsSorted)
            {
                String title = BuildUploadTitle(upload);
                var existingHeader =headers.FirstOrDefault(h => h.Title == title);

                if (existingHeader == null)
                {
                    Header newHeader = new Header();
                    newHeader.Title = BuildUploadTitle(upload);
                    newHeader.ToggleCommand = new SimpleCommand<object,string>( s => ToggleColumn(newHeader,s));
                    newHeader.ToggleAllCommand = new SimpleCommand<object, object>(o => ToggleFullColumn(newHeader));
                    newHeader.Hosters =
                        episodesSorted.SelectMany(e => e.Downloads)
                            .Where(d => d.Upload == upload)
                            .SelectMany(d => d.Links.Keys)
                            .Distinct().ToList();
                    headers.Add(newHeader);

                    DataGridTemplateColumn column = new DataGridTemplateColumn();
                    column.Header = newHeader;
                    column.HeaderTemplate = new DataTemplate();
                    column.HeaderTemplate.VisualTree = new FrameworkElementFactory(typeof (MultiDownloadSelectionHeader));
                    column.HeaderStyle = (Style) FindResource("CenterGridHeaderStyle");
                    column.CellTemplate = new DataTemplate();
                    column.CellTemplate.VisualTree = new FrameworkElementFactory(typeof (MultiDownloadSelectionCell));
                    column.CellTemplate.VisualTree.SetBinding(DataContextProperty, new Binding("Cells[" + i + "]"));

                    dgrid.Columns.Add(column);

                    i++;

                }
                else //there's already an upload existing (maybe in another Season) with the same string represenation
                {
                    existingHeader.Hosters = episodesSorted.SelectMany(e => e.Downloads)
                           .Where(d => d.Upload == upload)
                           .SelectMany(d => d.Links.Keys).Union(existingHeader.Hosters)
                           .Distinct().ToList();
                }
            }

            DataGridTemplateColumn fColumn = new DataGridTemplateColumn();
            fColumn.HeaderStyle = (Style)FindResource("RemovedHeaderContentStyle");
            fColumn.Width = new DataGridLength(1,DataGridLengthUnitType.Star);
            dgrid.Columns.Add(fColumn);

            List<Row> rows = new List<Row>();
            foreach (var episode in episodesSorted)
            {
                Row r = new Row();
                r.Title = "S" + episode.Season.Number + " E" + episode.Number;
                if (episode.EpisodeInformation != null && !String.IsNullOrWhiteSpace(episode.EpisodeInformation.Title))
                {
                    r.Tooltip = episode.EpisodeInformation.Title;
                }
                r.Cells = new List<Cell>();

                bool firstSelected = true;

                foreach (var header in headers)
                {
                    var c = new Cell();
                    c.Header = header;
                    c.Entries = new List<CellEntry>();
                    c.Episode = episode;

                    DownloadData dloads = episode.Downloads.FirstOrDefault(da => BuildUploadTitle(da.Upload) == header.Title);
                    bool selected = dloads!=null && dloads.Upload.Favorized;
                    if (firstSelected && selected)
                    {
                        firstSelected = false;
                    } else if (!firstSelected)
                    {
                        selected = false;
                    }


                    foreach (var hoster in header.Hosters)
                    {
                        if (dloads!=null && dloads.Links.ContainsKey(hoster))
                        {
                            c.Entries.Add(new CellEntry {Visibility = Visibility.Visible,Enabled=true, Link = dloads.Links[hoster], Checked = selected});
                        }
                        else
                        {
//.........这里部分代码省略.........
开发者ID:punker76,项目名称:sjupdater,代码行数:101,代码来源:MultiDownloadSelectionGrid.xaml.cs

示例13: ChangeLanguage

        /// <summary>
        /// Sprache wechseln
        /// </summary>
        /// <param name="culture">specific culture</param>
        public void ChangeLanguage(string culture)
        {
            // Alle Woerterbuecher finden
            List<ResourceDictionary> dictionaryList = new List<ResourceDictionary>();
            foreach (ResourceDictionary dictionary in System.Windows.Application.Current.Resources.MergedDictionaries)
            {
                dictionaryList.Add(dictionary);
            }

            // Woerterbuch waehlen
            string requestedCulture = string.Format("Cultures/CultResource.{0}.xaml", culture);
            ResourceDictionary resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
            if (resourceDictionary == null)
            {
                // Wenn das gewuenschte Woerterbuch nicht gefunden wird,
                // lade Standard-Woerterbuch
                requestedCulture = "Cultures/CultResource.xaml";
                resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
            }

            // Altes Woerterbuch loeschen und Neues hinzufuegen
            if (resourceDictionary != null)
            {
                System.Windows.Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
                System.Windows.Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
            }

            // Hauptthread ueber neues Culture informieren
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(culture);
            Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
        }
开发者ID:rest1014,项目名称:RoadRunner,代码行数:35,代码来源:Start.xaml.cs

示例14: AdjustMargins

        private void AdjustMargins(IHtmlView htmlView, List<Grid> controls)
        {
            var firstControl = controls.FirstOrDefault();
            if (firstControl != null)
                firstControl.Margin = new Thickness(0, htmlView.ParagraphMargin, 0, 0);

            var lastControl = controls.LastOrDefault();
            if (lastControl != null)
                lastControl.Margin = new Thickness(0, 0, 0, htmlView.ParagraphMargin);
        }
开发者ID:RareNCool,项目名称:MyToolkit,代码行数:10,代码来源:UlGenerator.cs

示例15: AddToHitline

            private static void AddToHitline(ref int runningSum, List<Tuple<int, List<Point3D>>> sets, int index, Tuple<Point3D, Point3D> hit, double entryRadius, double exitRadius, double maxAxisLength, Random rand)
            {
                Point3D[] points = GetVoronoiCtrlPoints_AroundLine_Cone(hit.Item1, hit.Item2, rand.Next(2, 5), entryRadius, exitRadius, maxAxisLength);

                runningSum += points.Length;

                var existing = sets.FirstOrDefault(o => o.Item1 == index);
                if (existing == null)
                {
                    existing = Tuple.Create(index, new List<Point3D>());
                    sets.Add(existing);
                }

                existing.Item2.AddRange(points);
            }
开发者ID:charlierix,项目名称:AsteroidMiner,代码行数:15,代码来源:MadShatter.xaml.cs


注:本文中的System.Windows.Documents.List.FirstOrDefault方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。