{"id":673,"date":"2018-05-28T07:37:52","date_gmt":"2018-05-28T07:37:52","guid":{"rendered":"http:\/\/sezeromer.com\/?p=673"},"modified":"2023-02-26T23:39:55","modified_gmt":"2023-02-26T20:39:55","slug":"listview-command-parameter-kullanimi","status":"publish","type":"post","link":"https:\/\/sezeromer.com\/en\/listview-command-parameter-kullanimi\/","title":{"rendered":"ListView Using Command Parameter"},"content":{"rendered":"<p><strong>ListView<\/strong> is one of the controls we use the most in <strong>Xamarin<\/strong>. We must use the <strong>ListView<\/strong> to display the data we have received from any place on a regular basis. While using the <strong>ListView<\/strong>, we can also send data in any control we have included. Take a list of recipes, for example. Get the vegetables to be eaten in this listen. Be a button with which we can get information about these vegetables or fruits. When we click on this button, we will get the <strong>CommandParameter<\/strong> to know which of the vegetables is clicked.<\/p>\n<p>First we will create a model called Vegetables to ensure that our data are always the same species. Vegetables name, calorie and price.<\/p>\n<p>Once we have created the vegetable model, we can start designing. We will keep every vegetable we create in a sequential order in the ListView. Vegetable name, price and calorie will be displayed while showing on the screen. We will also put a search button on them for easy research.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1238\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/05\/commandparameter-1.png\" alt=\"\" width=\"366\" height=\"673\" \/><\/p>\n<p>Now we come to the <strong>CommandParameter<\/strong> limit. We will give the name of each of the vegetables as Buton CommandParameter. We will do this on xaml side. I will share the code for Design and CommandParameter here. <strong>Xaml<\/strong> party;<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\"> &lt;StackLayout&gt;\r\n        &lt;ListView x:Name=\"listeYemek\"\r\n                 ItemsSource=\"{Binding .}\"\r\n                 &gt;\r\n            &lt;ListView.ItemTemplate&gt;\r\n                &lt;DataTemplate&gt;\r\n                    &lt;ViewCell&gt;\r\n                        &lt;ViewCell.View&gt;\r\n                            &lt;Grid&gt;\r\n                                &lt;Grid.ColumnDefinitions&gt;\r\n                                    &lt;ColumnDefinition Width=\"*\"\/&gt;\r\n                                    &lt;ColumnDefinition Width=\"*\"\/&gt;\r\n                                    &lt;ColumnDefinition Width=\"*\"\/&gt;\r\n                                    &lt;ColumnDefinition Width=\"*\"\/&gt;\r\n                                &lt;\/Grid.ColumnDefinitions&gt;\r\n                                &lt;Label Text=\"{Binding SebzeAd}\"\r\n                                       HorizontalTextAlignment=\"Center\"\r\n                                       Grid.Column=\"0\"\r\n                                       TextColor=\"Black\"\/&gt;\r\n                                &lt;Label Text=\"{Binding Kalori}\"\r\n                                       HorizontalTextAlignment=\"Center\"\r\n                                       Grid.Column=\"1\"\r\n                                       TextColor=\"Black\"\/&gt;\r\n                                &lt;Label Text=\"{Binding Fiyat}\"\r\n                                       HorizontalTextAlignment=\"Center\"\r\n                                       Grid.Column=\"2\"\r\n                                       TextColor=\"Black\"\/&gt;\r\n                                &lt;Button Text=\"Ara\"\r\n                                        BackgroundColor=\"Blue\"\r\n                                        TextColor=\"White\"\r\n                                        BorderWidth=\"2\"\r\n                                        BorderRadius=\"15\"\r\n                                        BorderColor=\"Red\"\r\n                                        x:Name=\"buttonAra\"\r\n                                        Grid.Column=\"3\"\r\n                                        Clicked=\"buttonAra_Clicked\"\r\n                                        CommandParameter=\"{Binding SebzeAd}\"\/&gt;\r\n                            &lt;\/Grid&gt;\r\n                        &lt;\/ViewCell.View&gt;\r\n                    &lt;\/ViewCell&gt;\r\n                &lt;\/DataTemplate&gt;\r\n            &lt;\/ListView.ItemTemplate&gt;\r\n        &lt;\/ListView&gt;\r\n    &lt;\/StackLayout&gt;<\/pre>\n<\/div>\n<p>After sending vegetables names with CommandParameter, we need to get these parameters in .cs. The button gets two variables from the outside in the click event. One of them is the sender. We take this button by casting it because it is a sender button. After that, we take the CommandParameter of the button and hold it in a variable. Finally, we succeed in this screen.<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;swift&quot;,&quot;mime&quot;:&quot;text\/x-swift&quot;,&quot;theme&quot;:&quot;default&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:false,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:true,&quot;align&quot;:&quot;&quot;}\"> private void buttonAra_Clicked(object sender, EventArgs e)\r\n        {\r\n            Button btn = (Button)sender;\r\n            var sebzead = btn.CommandParameter.ToString();\r\n            DisplayAlert(\"Sebze Ad\u0131\", sebzead, \"OK\");\r\n        }<\/pre>\n<\/div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1241\" src=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/05\/commandparameter-2.png\" sizes=\"(max-width: 366px) 100vw, 366px\" srcset=\"http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/05\/commandparameter-2.png 366w, http:\/\/sezeromer.com\/wp-content\/uploads\/2018\/05\/commandparameter-2-163x300.png 163w\" alt=\"\" width=\"366\" height=\"673\" \/><\/p>\n<p>If you have any questions, you can reach us by email or comment.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>ListView is one of the controls we use the most in Xamarin. We must use the ListView to display the data we have received from any place on a regular basis. While using the ListView, we can also send data in any control we have included. Take a list of recipes, for example. Get the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1238,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[289,288,3],"tags":[114,464,139,462,463,115,457,249,461,8,465,22,119],"class_list":["post-673","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","category-ios","category-xamarin-ile-yapilmis-projeler","tag-android","tag-binding","tag-button","tag-command","tag-commandparameter","tag-ios","tag-list","tag-liste","tag-listview","tag-omer","tag-sezezr","tag-xamarin","tag-xamarin-forms"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/673"}],"collection":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/comments?post=673"}],"version-history":[{"count":9,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/673\/revisions"}],"predecessor-version":[{"id":2592,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/posts\/673\/revisions\/2592"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media\/1238"}],"wp:attachment":[{"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/media?parent=673"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/categories?post=673"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sezeromer.com\/en\/wp-json\/wp\/v2\/tags?post=673"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}