I converted my code from UserControl1 to C# only, except the ItemTemplate of the legend which is stored in the Application Resources dictionary. Check the attached project. I hope this is a good starting point for implementing your requirement in code-behind.
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin
, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.