Archives - Category: Dev - page 3

  • Explorations in Cross-Platform Assets: 9-Slice Stretchable SVGs in Xamarin.Forms Apps

    There comes a time in cross-platform development where you inevitably long for a simpler mechanism for dealing with the deluge of image assets. You end up with three or more sizes of every single image with different names for every platform. At Twin, SVGs have risen to that challenge for us, and we use it everywhere we can with a custom variant of Paul Patarinski’s SvgImage control. After some minimal setup work to start using them, they render crisply at any size and resolution we throw at them.

  • Cross-Platform Images in Xamarin.Forms Using SVGs

    Screenshot from the demo app; code available via GitHub, showing the flexibility of SVGs.

    For the last four months, I’ve been working on a fast-paced Xamarin.Forms project where almost every image used has been an SVG shared between both the iOS and the Android platform apps. And it has been glorious! If an early UI design needed a few pixels shaved or added to an image we were using, no new images were needed, let alone a handful of pixel-density variations on it. It was just the few lines of code or XAML to change the rendered size. (In fact, I’ve extended our use to include stretchable buttons by adding 9-slice SVG support.) With SVGs, you use one tiny XML file to render the resulting image at any size or for any screen density.

    TL;DR

    1. Put SVGs in a PCL as an EmbeddedResource build action
    2. Use an SVG control (I recommend TwinTechsForms.NControl.SvgImageView, but there are other choices.)
    3. Add an SvgImageView to your C# or XAML UI the the right assembly and resource path
  • Return of Netduino, .NET on small hardware

    A little piece of magic wandered into my Twitter feed recently. Between the Windows IoT stuff I messed with this summer, controlling LEDs via Xamarin.Forms, and this awesome news, I’m bound to be learning the hardware side of things a little better.

  • Adding HTTPS to WordPress with Cloudflare

    patridgedev.com with a fancy green "Secure" padlock

    With some helpful pursuasion from Planet Xamarin, I decided my blog needed to support HTTPS requests. I’ve wanted to find a way to support HTTPS traffic on my blog for a while, but I wanted to find a solution that would Just Work™ without me doing the leg work. I’ll stick to writing the blog posts and let someone else worry about hosting details.

    Just like anything security-related, setting up SSL intimidates me a bit (more so because this often involves the dark magic of DNS records). I’ll do security when I have to, but my prerequisite is always that I read so much about the topic I feel comfortable explaining every decision I make to either an expert or someone completely unfamiliar with the topic.

  • Cleaning up unused images in your Markdown content with PowerShell

    I was recently tasked with cleaning up some Markdown content with a bunch of screenshots. Sometimes as content was revised, an image would no longer be used, but the image wasn’t deleted. As a result, the images folder would often be packed with files that were no longer used in the final Markdown content.

    On a few blocks of content, I would do this manually in VS Code. From the file list (Ctrl+Shift+E), I’d select the file, copy the file name (F2, then Ctrl+C), search all the files for that file name (Ctrl+Shift+F, then Ctrl+V). This was painful to do for more than a few blocks, so I decided to turn to automation, Powershell in this case.

    PowerShell is available on Windows and Linux/macOS, so it’s great for wherever I need it. It even seems to properly translate my path separators on different platforms.

  • Making a custom `dotnet new` template

    Why make a template

    I am a bit biased these days, but once I spin up a folder structure and/or text document manually more than twice, I give some thought to templating it. If I need to keep making more of something, the time to get all the boilerplate content in place is time taken away from the good stuff I want to write.

    This is the first in a series of posts about creating custom templates for the dotnet new system.

  • Add variables to your custom `dotnet new` template

    Previously, I covered creating your first custom dotnet new template. Now, let’s work on customizing the content our template generates based on inputs provided via the command line. I’ll be working from the same custom template from that post, which is just a dotnet new console output with its own .template.config setup. If you want a starter template project to get you going, use the template from the 1-custom-template folder from the Git repo from that blog post.

    This is the second in a collection of posts about creating custom templates for the dotnet new system.

  • Fallback variables in `dotnet new` templates

    Previously, we created our first custom dotnet new template and added our first input parameter for it. Next, let’s get a little more advanced with our parameters to make our life easier. In this post, we’ll create a template symbol that will function like a coalesce operator, taking a preferred input but falling back to a different input if the preferred value is not found.

    This is the third in a collection of posts about creating custom templates for the dotnet new system.

  • Workaround: Xamarin.Android long paths on Windows

    Quick answer (TL;DR)

    Create a symbolic link from your deeply-nested folder to a shorter path using one of the following commands in an Administrator prompt.

    Command Prompt

    mklink /D {desired-path-location} {actual-path-location}
    

    PowerShell [Core]

    New-Item -ItemType SymbolicLink -Path {desired-path-location} -Value {actual-path-location}
    

    After you create the symbolic link, drag the desired solution into Visual Studio rather than navigating through the link in the Open dialog, which will override to the original path.

  • Determine SHA hash of file on Windows, Linux, and macOS

    While it doesn’t guarantee a download hasn’t been compromised, sometimes you feel better knowing the file you downloaded matches the expected SHA hash.

    Full disclosure here: while I haven’t been paid or provided anything for this blog post, I am only creating this post for me. If it helps you, great! I just keep looking this up every time I need it. Instead of wading through a bunch of Stack Overflow answers to find the exact magic command I need, I’m hoping I’ll start finding my own blog post in my search results.