Xamarin Tips: Xamarin Forms Checkbox
There are no checkbox controls in Xamarin Forms. You can build the custom components with the custom renderers for this purpose. That is very complex. I chose to use a simpler way, using an Image control and TapGestureRecognizer. If the image is checked, then print the checked image, otherwise, just print an empty square. That is easy.
Code
this.chkbox.GestureRecognizers.Add(new TapGestureRecognizer | |
{ | |
TappedCallback = (v, o) => | |
{ | |
if (!checked) | |
{ | |
chkbox.source = ImageSource.FromFile("checked.png"); | |
checked = true; | |
} else{ | |
chkbox.source = ImageSource.FromFile("unchecked.png"); | |
checked =false; | |
} | |
} |
Xamarin Tips: Visual Studio is not responding after stoping an iOS app.
I found there are a number of times, in Visual Studio, when I stopped an iOS app. My visual studio became not responding and holding up for more than a minute. I found the issue, that may be because of I used a Mac Book and a real PC(not a VM) to build, there may have network issues. The issue is between iOS build host and Visual Studio. After I close iOS Build Host, and open it again, then visual studio is working normally.
Xamarin : Access style in the code behind
I defined all styles in app.xaml, which is a kind of css style and that is the centralised place to manage the look and feel. I think that is a good practice. That is no problems to access the style across other xaml file. But in code behind, how do I get it working
That is simple,
Code
txt.Style= (Style) Application.Current.Resources["name"] |
Please don't user only Resources["name"] which is only calling Resources Dictionary in your local xaml, not global app.xaml. You will get a NullReferenceException
Disable Scroll Bar in ListView
I am building an app which has a number of listviews, for some phone it will be longer than its screen. So a global scroll bar are required. However, the listview has their own scrollbar bar, It will make scrolling some strange! Thus, I need to disable all scrollbar, only leaving the global bar.
There are no properties in ListView control to disable its scroll bars. The only way to do that is set HeightRequest to a super big number.
I wish in their future version can have this useful feature.
PCL vs Shared Projects in Xamarin Forms
I am not an expert in Xamarin. I only have spent 6 months on this programming platform. Thus, please feel free to response this post.
My frist preference is to Shared Projects. That is easier to manage. I can share xmal files across each project. That is simple, I think that is good to use in a small and one-off project.
However, if you have more focus on reuse, I think you choose PCL. That is more like a standard control library. You can use the controls in the library easily! Also, you are building a larger scale project, I think that is safer to use PCL, because PCL is more self-contained.
I think using PCL or Shared Projects is depending your project scale and goals.