Archive for the ‘WinRT’ Category
Compile SQLite for WinRT with FTS4 unicode61 support
I was experimenting with the FTS3/FTS4 feature of SQlite in a WinRT app. The default tokenizer ‘simple’ wont tokenize special character like $, @, etc. The solution is to use ‘unicode61’ tokenizer. Unfortunately the SQLite installer for WinRT8.1 comes without unicode61 tokenizer. I searched a lot to get a SQlite WinRT build that supports unicode61 but I was not lucky enough to get one, so I decided to build one myself.
Tim Heuer have a great post explaining about creating a build of SQLite for WinRT, I went through that and acquired all the tools to build, including the SQLite source code. I did exactly the same way Tim explained in the video, finally I got my build. But again it has the same issue, not supporting unicode61 tokenizer. I tried several builds and all these time I build with DSQLITE_ENABLE_FTS4_UNICODE61=1 and other flags I mentioned below.
After several attempt with so many permutations and combinations, I got it working. Tim’s video is a very good reference for building SQLite for WinRT. But if you want unicode61 support then follow the below steps, it’s same as Tim’s explained with some exclusion.
- mkdir c:\sqlite
- cd sqlite
- fossil clone http://www.sqlite.org/cgi/src sqlite3.fossil
- fossil open sqlite3.fossil
fossil checkout winrt,never issue this command, it will never include unicode61- Added this step to enable unicode61 tokenizer. Append the below config to Makefile.msc, you can see some config already existing append the below config to it.
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS3_PARENTHESIS=1
OPT_FEATURE_FLAGS = $(OPT_FEATURE_FLAGS) -DSQLITE_ENABLE_FTS4_UNICODE61=1
- Compile the code by issuing nmake -f Makefile.msc sqlite3.dll FOR_WINRT=1
I could build X86 and X64 using VS2012 command prompt for X86 and X64. But when I tried to compile for ARM I was getting some errors, I was fortunate enough to find a solution in StackOverflow. Followed that solution and I got the SQLite builds for X86, X64 and ARM.
I don’t want to spend time in creating a vsix package and install it in my machine, instead I took the backup of SQLite for WinRT version 3.8.5, in my machine the installed path is C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\SQLite.WinRT81. Then went into each folder and replaced the lib and sqlite dll with the respective builds I created.
Leave your comments if you have any questions.
Happy coding…
WinRT TextBlock with HyperLinks
I was doing some experiments with Window 8 app development. I wanted to show the text in a TextBlock with any URL as a clickable hyperlink, so that user can click on it and navigate to that webpage. We can do this easily via xaml as shown below. I googled a lot to find a way to do the same in MVVM approach. With no solution in hand I decided to come up with a solution using Attached Properties.
<TextBlock x:Name="textValue" TextWrapping="Wrap"> <TextBlock.Inlines> <Run Text="This is an example of how Hyperlink can be used in a paragraph of text.
It might be helpful for you look to"></Run> <Hyperlink NavigateUri="www.bing.com">bing</Hyperlink> <Run Text="for more answers in the future."></Run> </TextBlock.Inlines> </TextBlock>
I am using Caliburn Micro to bind the text, so the above approach will not suit my requirement. The solution I come up with is Custom Attached Properties. In the Attached properties I applied the above logic but via code. Have a look at the code.
using System; using System.Text; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; using Windows.UI.Xaml.Documents;
namespace Test.App.AttachedProps { public class HyperLinkedTextBlock { public static string GetText(TextBlock element) { if (element != null) return element.GetValue(ArticleContentProperty) as string; return string.Empty; } public static void SetText(TextBlock element, string value) { if (element != null) element.SetValue(ArticleContentProperty, value); } public static readonly DependencyProperty ArticleContentProperty = DependencyProperty.RegisterAttached( "Text", typeof(string), typeof(HyperLinkedTextBlock), new PropertyMetadata(null, OnInlineListPropertyChanged)); private static void OnInlineListPropertyChanged(DependencyObject obj,
DependencyPropertyChangedEventArgs e) { var tb = obj as TextBlock; if (tb == null) return; string text = e.NewValue as string; tb.Inlines.Clear(); if (text.ToLower().Contains("http:") || text.ToLower().Contains("www.")) AddInlineControls(tb, SplitSpace(text)); else tb.Inlines.Add(GetRunControl(text)); } private static void AddInlineControls(TextBlock textBlock, string[] splittedString) { for (int i = 0; i < splittedString.Length; i++) { string tmp = splittedString[i]; if (tmp.ToLower().StartsWith("http:") || tmp.ToLower().StartsWith("www.")) textBlock.Inlines.Add(GetHyperLink(tmp)); else textBlock.Inlines.Add(GetRunControl(tmp)); } } private static Hyperlink GetHyperLink(string uri) { if (uri.ToLower().StartsWith("www.")) uri = "http://" + uri; Hyperlink hyper = new Hyperlink(); hyper.NavigateUri = new Uri(uri); hyper.Inlines.Add(GetRunControl(uri)); return hyper; } private static Run GetRunControl(string text) { Run run = new Run(); run.Text = text + " "; return run; } private static string[] SplitSpace(string val) { string[] splittedVal = val.Split(new string[] {" "}, StringSplitOptions.None); return splittedVal; } } }
In the above code I analyze the text for urls after splitting it, you can also do it using RegEx. As this code is just for protyping, I didn’t pay much attention to the quality of it.
In the xaml page I refer this attached property as shown below.
xmlns:conv="using:Test.App.AttachedProps"
In the Textblock, bind the text via the attached property as shown below.
<TextBlock conv:HyperLinkedTextBlock.Text="{Binding TextVal}"/>
If the TextVal has any words that starts with ‘http:’ or ‘www.’ then the above Custom Attached Property will create a HyperLink other wise create a Run control and add it to the Inline collection of the TextBlock.
Happy coding…