How to add a custom user agent in the header using a webview and Xamarin Forms

I am writing an app using Xamarin Forms and wanted to control the user agent for my webview. It’s a little hacky way to have the website render differently when it see that it’s my app coming in without having to use session cookies or other crap like that.

It was pretty easy once I found the code, but finding the code was the pain. Well, Add this renderer to your IOS project.


using Foundation;
using PrazeMeApp.iOS.Renderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(WebView), typeof(MyWebViewRenderer))]
namespace PrazeMeApp.iOS.Renderers
    public class MyWebViewRenderer : WebViewRenderer
            protected override void OnElementChanged(VisualElementChangedEventArgs e)
            NSDictionary dictionary = NSDictionary.FromObjectAndKey(NSObject.FromObject("myuseragentgoeshere"), NSObject.FromObject("UserAgent"));


Happy Coding!

How to center or right align the Header in the WPF RadGridView by Telerik?

Telerik is not the best at providing documentation on how to do things, so I figured I would write some of the more mundane tasks that took me a few minutes thought.

Here, I needed to center my headers. It is easy but only if you know all the magic words. If you don’t, it is pretty hard.

Here is how you do it. A simple style.


        <telerik:RadTreeListView ItemsSource="{Binding Nodes}" AutoGenerateColumns="False" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                               IsExpandedBinding="{Binding IsExpanded,Mode=TwoWay}"                                 
                             SelectedItem="{Binding SelectedNode,Mode=TwoWay}"
                <Style BasedOn="{StaticResource {x:Type telerik:GridViewHeaderCell}}" TargetType="{x:Type  telerik:GridViewHeaderCell}">
                    <Setter Property="HorizontalContentAlignment" Value="Center"/>

Happy Coding!

How to put bound data (Binding) into a Grid View Header or List View Header.

This is another seemingly simple task. It actually is, but you may go down the route of setting the GridViewHeader.Template and wondering why it doesn’t work.

Well, it’s as simple as putting a GridViewHeader into the GridViewColumn definition and setting content to it.

<GridViewColumn  Width="Auto">
        <Grid HorizontalAlignment="Right" >
                <TextBlock Text="{Binding Title, Mode=OneWay}" Grid.Row="0" HorizontalAlignment="Right" />

See. Nice and easy right? Just fill in the different UI controls you want to make it fit your needs and away you go.

Happy Coding!

Visual C++, Precompiled Headers and Windows 7

I upgraded to Windows 7 and I really am enjoying the new interface….but….. I went to compile my ActiveX toolset projects that are all written in C++ and I started getting  precompiled header errors.

So I rebuilt and rebuilt and still got the error:

Error    1    fatal error C1859: ‘.Release/HTTP Wizard.pch’ unexpected precompiled header error, simply rerunning the compiler might fix this problem    d:SSIC++v3HTTP Wizard v3HTTPAccess.cpp    5    HTTP Wizard

So I rebuilt and rebuilt. No avail. I turned off Precompiled headers and then everything worked fine. What a pain.

It turned out the reason is due to the virtual tables being rebased by Windows 7 for security which totally screws up the precompiled header logic, which requires the headers to be in the same memory locations.

Apparently the development team at Microsoft knows about the issue and will eventually fix it. So, lets hope that service pack comes out soon.

I guess I am lucky my build machine is really beefy, but for active development having the precompiled header is nice.

So, go have a Margarita and the  compiler errors won’t bother you as much…..