Category Archives: Computers and Internet

How to stop Facebook from stealing your attention

There are times when you check Facebook to just fill a free minute or post something and then you find you’ve been pulled into the vortex of links worth clicking. You can unfollow everyone and everything until your timeline slows down, but then they give you trending topics, suggested pages, ads etc. Well, today you can switch your Facebook from looking like this:
Continue reading

Advertisements
Tagged , , , ,

High performance XAML charts… using Win2D

ScreenCap

Hi! 

Over the last couple of years I got quite a few questions about the Chart control that I ported from Silverlight Toolkit and shared in WinRT XAML Toolkit. Mostly about performance and customizing the design. Well, the update performance is something I recently tweaked a little bit by removing some of the animations, but really – the control is fairly complicated and uses lots of XAML to enable customizing all the different parts and so it works best for static charts with just a few data points. I haven’t actually used the control much, so every time I get asked how to change anything in it – I have to investigate it myself and often get lost in all that code.

Continue reading

Tagged , , ,

Setting and checking flags in MSBuild projects

I’ve been looking into ways to temporarily stop trying to access a network share for a while if I can’t access it in an MSBuild project. The thing is – sometimes trying to access a network share takes a really long time and if your target is executed many times by various projects – it could really slow things down and if accessing that share is only desired, but not required – it would be bad to slow things down so badly. One way I thought was interesting was to set a file or registry value as a flag based on the date, so that I will stop trying for the day, but retry the next day. Here’s how I’ve done it:

File flag

<PropertyGroup>
    <TodaysDate>$([System.DateTime]::Now.ToString("yyyyMMdd"))</TodaysDate>
    <ShareErrorFlagFile>ShareAccessError_$(TodaysDate).flag</ShareErrorFlagFile>
    <SharePath
        Condition="
            '$(SharePath)' == '' And
            !Exists($(ShareErrorFlagFile)) And
            Exists('\\machine\folder')">\\machine\folder</SharePath>
    <SharePath
        Condition="
            '$(SharePath)' == '' And
            !Exists($(ShareErrorFlagFile)) And
            Exists('\\machine2\folder')">\\machine\folder</SharePath>
</PropertyGroup>

<Target
    Name="test">
    <CallTarget
        Condition="'$(SharePath)' == ''"
        Targets="HandleShareAccessError" />
    <CallTarget
        Condition="'$(SharePath)' != ''"
        Targets="DoSomething" />
</Target>

<Target
    Name="HandleShareAccessError">
    <Message
        Text="Could not reach SharePath"
        Importance="high" />
    <Exec
        Command="echo Failed to access build tracker install share today. Delete this file to try again. $(ShareErrorFlagFile)" />
</Target>

Registry value

<PropertyGroup>
    <TodaysDate>$([System.DateTime]::Now.ToString("yyyyMMdd"))</TodaysDate>
    <SharePath
        Condition="
            '$(SharePath)' == '' And
            '$(registry:HKEY_CURRENT_USER\SOFTWARE\Contoso\MyApp@DisabledForDay)' != '$(TodaysDate)' And
            Exists('\\machine\folder')">\\machine\folder</SharePath>
    <SharePath
        Condition="
            '$(SharePath)' == '' And
            '$(registry:HKEY_CURRENT_USER\SOFTWARE\Contoso\MyApp@DisabledForDay)' != '$(TodaysDate)' And
            Exists('\\machine2\folder')">\\machine\folder</SharePath>
</PropertyGroup>

<Target
    Name="test">
    <CallTarget
        Condition="'$(SharePath)' == ''"
        Targets="HandleShareAccessError" />
    <CallTarget
        Condition="'$(SharePath)' != ''"
        Targets="DoSomething" />
</Target>

<Target
    Name="HandleShareAccessError">
    <Message
        Text="Could not reach SharePath"
        Importance="high" />
    <Exec
        Command="reg add HKCU\Software\Contoso\MyApp /v DisabledForDay /t REG_SZ /d $(TodaysDate) /f" />
</Target>

The registry key solution is slightly cleaner – it doesn’t generate date-stamped files in every place you run it, but the file-based one is more discoverable and so when you clean the directory where you run it – it will try to access the share again.

Tagged

Exiting a WPF app

So this is a developing story. I’m working on a WPF app again these days and how do you exit a WPF when you’re done running? Normally a user or your code might close the main/last window and the app would exit, but what else can you do?

  • Application.Current.Shutdown() is what I’ve been trying and it wouldn’t work. Why? It turns out – it needs to be invoked on the dispatcher thread… ugh. Anyways – it seems to be THE WPF way, so I’m sticking with it:
    Application.Current.Dispatcher.Invoke(Application.Current.Shutdown);
  • Environment.Exit(0) should work WPF or not.
  • Process.GetCurrentProcess().Kill() is a rather sudden, but sure way to kill your own process.
Tagged ,

Cannot deserialize XBF metadata type list as NullableBoolToBoolConverter was not found in namespace

I was trying to get something working last night and kept hitting this exception when my app was trying to InitializeComponent() at one point.

CannotDeserializeXbf

First-chance exception at 0x750D1D4D in App1.exe: Microsoft C++ exception: Platform::COMException ^ at memory location 0x037CDDC0. HRESULT:0x802B000A The text associated with this error code could not be found.

WinRT information: Windows.UI.Xaml.Markup.XamlParseException: The text associated with this error code could not be found.

Cannot deserialize XBF metadata type list as ‘NullableBoolToBoolConverter’ was not found in namespace ‘WinRTXamlToolkit.Converters’. [Line: 0 Position: 0]

at Windows.UI.Xaml.Application.LoadComponent(Object component, Uri resourceLocator, ComponentResourceLocation componentResourceLocation)

All this seemed complete and utter bogus, since NullableBoolToBoolConverter was obviously there and it would work perfectly well in other projects or solution configurations, so let’s look what was happening.

  • NullableBoolToBoolConverter is defined in WinRTXamlToolkit – a .NET Class Library that I’d typically build as Any CPU. It has a ton of controls, converters and other such goodies and of course it typically works just fine.
  • NullableBoolToBoolConverter is used in WinRTXamlToolkit.Debugging – another .NET Class Library that has an in-app XAML visual tree debugger tool – essentially a TreeView control that displays information about the visual tree of your application – hierarchy of UI elements and their properties. The main control in the library uses NullableBoolToBoolConverter and it normally works when used from a .NET Windows Store app.
  • The problem is that WinRTXamlToolkit.Debugging is a .NET Class Library and there is still a small, but important range of WinRT XAML apps written in C++ that can’t use it, so I created a managed WinRT component library – WinRTXamlToolkit.Debugging.WinRTProxy that C++/CX projects can reference. It’s fairly straightforward to do it seems – you just create a proxy class in the WinRT Component library that has methods that invoke methods in the referenced class library (WinRTXamlToolkit.Debugging) and now you can use it from C++/CX. I prefer to keep WinRTXamlToolkit.Debugging a regular .NET class library because WinRT Components have limitations that would limit the APIs I currently have in WinRTXamlToolkit.Debugging. The proxy methods in the WinRTProxy library still have these limitations, but at least I can use it from a native app. The problem is that it wouldn’t work and keep giving me that exception, so what’s up?

It turns out WinRT XAML generates these files – XamlTypeInfo.g.cs that allow the XAML parser to see the types it can use and I noticed that file was missing in the obj folder of WinRTXamlToolkit.Debugging.WinRTProxy. To get it to generate I simply added one empty UserControl to WinRTXamlToolkit.Debugging.WinRTProxy and everything started working fine! Weird but it works. So now I’m left with figuring out how to wrap this all as a NuGet component with native versions of the .NET libraries, since I’ve previously only packaged Any CPU binaries…

Tagged , , , , , ,

How to safely use your time while you build a project?

So your build takes a while… How do you make use of that time (e.g. check Stack Overflow) and not forget to get back to work when the build is done? Well, you can make a sound. I am not sure if there is a simple built-in option to Visual Studio allows to play sounds on events. It is quite possible there is, but I will use what I know. I found you can play a sounds in command line by typing echo ^G, but it didn’t seem to work for me in a VS project post-build step. I blogged about using batch scripts and C# code together in a single file and here’s a way to beep from a batch script:

Continue reading

Tagged , ,

The five minute gauge control for WinRT/XAML

Wow, gauge controls are pretty easy to implement. Why would anyone pay for one? 🙂

This one took me literally 5 minutes. True, it is just a UserControl and it only shows 0-360 values I needed to debug some compass code, but it’s easy to build on it so I thought I’d share it since all my other blog post ideas need quite a bit more time than 5 minutes… 🙂

gauges

Continue reading

Tagged , , , ,

My Short Opinion About Windows Store Apps

I really like Windows 8. I like the improvements on the desktop side. I like the new start screen better than the old start menu. I like the WinRT technology, design and interactivity of the Windows Store apps. I love the cloud integration of the OS and apps. I believe this is the most user friendly OS for tablets on the WinStore apps side and the most user friendly and powerful OS on the desktop side.

I don’t really use any Windows Store apps though, since I don’t own a Windows 8 tablet and mostly use Windows on a (touch screen) laptop. I think this will be a great platform for games and I believe the AAA titles should and will come out in Windows Store and I will play some of them – perhaps even on my desktop machine since it has better GPU and cooling than my ThinkPad. For the apps on a laptop or desktop machine though – I think the desktop platform is still better. I like my apps in windows, system tray (or as Windows people like to call it – notification area) and I like having all of them on my screen and a consistent taskbar where I see all of them. On the desktop – I like seeing all my 100 open tabs in Chrome, 5 instances of Visual Studio, Outlook, etc. I like that I can play a video in a window and then continue listening to the video (or a webcast) while I move its window behind my Visual Studio window and continue working.

I think things might change – I would love if Microsoft added all the more line of business controls and WPF features to the WinRT platform – such as grid splitters, data grids, tree views etc. I would like to be able to develop windowed applications in WinRT, though I am afraid Microsoft is much more likely to insist on making the full-screen experience more powerful rather than supporting the good old lowercase windows.

I am excited for the future.

Tagged

Layout and Formatting with Windows 8 XAML Development

When designing a user experience, one of the first things you need to figure out is where to position things on the screen, how they should flow when the content changes, and what shape or color they should be. This article is about the tools you have at your disposal with Windows 8 XAML to control layout and formatting on this exciting new platform.

Read more on Safari Books Online

Tagged , ,

Windows 8 Development with XAML and C# – New and Missing Controls

Although the Windows 8 XAML platform brings back a lot of the controls that exist in WPF and Silverlight, and adds some completely new ones, there are some controls that you might find missing and wonder what to do. In this article we cover a list of some of these controls, along with some suggested ways to cope with their loss.

Read more on Safari Books Online

Tagged , , ,