0

This answer shows how to set the MinHeight of ListView items from XAML.

I can't figure out how to do this in C#. I tried looking for an appropriate argument for imageCell.SetBinding() and tried finding MinHeight as a property of ImageCell...

So - How do I do this in C#?

Community
  • 1
  • 1
ispiro
  • 26,556
  • 38
  • 136
  • 291
  • Create a style in C# instead of XAML, do all the other stuff he did but in C# instead of XAML, etc. etc. Or just do it in XAML. – 15ee8f99-57ff-4f92-890c-b56153 Jan 04 '17 at 18:37
  • Why is there a requirement for this XAML-without-XAML stuff? – 15ee8f99-57ff-4f92-890c-b56153 Jan 04 '17 at 18:39
  • @EdPlunkett `Create a style in C# instead of XAML` - That's exactly my question. This is what I have so far: `Style style = new Style(typeof(ListView)); style.Setters.Add(new Setter { Property = ListView.ItemTemplateProperty, Value = 30 });` Not much good, it seems. – ispiro Jan 04 '17 at 19:03
  • It's a non-XAML Xamarin project. – ispiro Jan 04 '17 at 19:05
  • OK, if you can't XAML, you can't. If you tried to create a style and apply it and it "seemed" not to be "much good", can you show us the actual code that didn't work for you? – 15ee8f99-57ff-4f92-890c-b56153 Jan 04 '17 at 19:07
  • @EdPlunkett I just did :(. I'm trying to emulate [this](http://stackoverflow.com/a/1729569/939213) answer, but apparently either I just don't know enough (hence my question), or perhaps it needs to be done a little differently in Xamarin. (I can't find a `MinHeight` to be used in a `Setter`'s `Property`.) – ispiro Jan 04 '17 at 19:10
  • You mean you created a style object and didn't do anything with it? You need to make it the `ItemContainerStyle` for the `ListView`, like he did. – 15ee8f99-57ff-4f92-890c-b56153 Jan 04 '17 at 19:11
  • @EdPlunkett I was just describing its creation. There was one more line: `listView.Style = style;`. But it's targeting `ItemTemplateProperty` and I need `MinHeight` anyway. – ispiro Jan 04 '17 at 19:12
  • @EdPlunkett `ListView.ItemContainerStyle` doesn't even exist in Xamarin. – ispiro Jan 04 '17 at 19:17
  • In that case you may have a serious problem. – 15ee8f99-57ff-4f92-890c-b56153 Jan 04 '17 at 19:19
  • The example you are working from is not a Xamarin example. It is for UWP. The tags are: c#, xaml, listview, win-universal-app, uwp. A UWP ListView is not the same as a Xamarin Forms ListView, thus the available properties will be different. Here is the API docs for a Forms Cell: https://developer.xamarin.com/api/type/Xamarin.Forms.Cell/ and a Forms ListView: https://developer.xamarin.com/api/type/Xamarin.Forms.ListView/ . There is no MinHeight property, only a Cell.Height property and a ListView.RowHeight property. – jgoldberger - MSFT Jan 05 '17 at 01:01
  • @jgoldberger Thanks. Unfortunately Xamarin ListViews are way too dense on UWP. (They're fine on Android.) And setting a fixed height is a hack that can be broken depending on screen resolution and "text size" settings. Thanks again. – ispiro Jan 05 '17 at 11:43

0 Answers0