Category Archives: Platforms and frameworks

HwndHost is not clipped inside ScrollViewer

I created a simple white control with a black border derived from HwndHost (named LightGrid) and added it to ScrollViewer along with some other controls (replaced with “…”) as shown below:

<ScrollViewer HorizontalScrollBarVisibility="Disabled">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            ...
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            ...
        </Grid.RowDefinitions>
        ...
        <Border Grid.Row="6" Grid.ColumnSpan="2" Visibility="Visible" Height="200">
            <nc:LightGrid />
        </Border>
    </Grid>
</ScrollViewer>

It looks correctly in the lower scroll position, and it even can scroll inside ScrollViewer (it moves when I move the scroll bar), but when scrolled, it is not clipped so it obscures other controls:

(more…)

Combining XAML and DirectX together in a WinRT application

With the release of Windows 8, Microsoft introduced a grate technology for combining XAML and DirectX together, letting us to place XAML controls over intensive real-time graphics, see DirectX and XAML interop (Windows Runtime apps using DirectX with C++) for more details.

You can easily download and build sample XAML SwapChainPanel DirectX interop sample demonstrating how it works. All that you need is Visual Studio 2013 with installed license. After the license is installed Visual Studio 2013 shows the following dialog:

Visual Studio 2013 license

(more…)

Using a WPF control in a MFC application

I’ve been working on some MFC application and to apply my WPF knowledge I added a WPF control written in C# to my MFC CView with the following code:

int CMyView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;

    try
    {
        gcroot<hwndsource ^> hwnd_source = gcnew HwndSource(0, WS_VISIBLE | WS_CHILD, 0, 0, 0, "HwndSource", IntPtr(m_hWnd));

        MyWpfControl ^ control = gcnew MyWpfControl();

        hwnd_source->RootVisual = control;
    }
    catch (Exception ^ ex)
    {
        String ^ msg = ex->Message;
    }

    return 0;
}

All that I needed to do is to follow the steps described in this post: How do I host WPF content in MFC Applications, fix VS2012 bug described here, and got rid of std::mutex and std::lock_guard replacing them with the following classes using typedefs:

(more…)

WPF TreeView does not support Data Virtualization

WPF implements UI Virtualization via VirtualizingStackPanel and it works great, but situation with Data Virtualization is a bit more complex.

After doing some experimentation I realized that VirtualizingStackPanel when used with WPF TreeView does not allow the data to be virtualized because it iterates through all the collection of data items from inside its MeasureOverride function. However, it access only visible data items when used with DataGrid or ListView, so it allows to use some paging or caching techniques in this case. See the following articles for more information:

If you interested on what I tried to do with TreeView, please read below.

(more…)

Generalization of auto_ptr<T> for working with Win32 API

A long time ago, STL had auto_ptr<Type> class that automatically deleted a dynamically allocated C++ object when control leaves a block. Personally, I believe that auto_ptr<Type> was typically used in simple scenarios as a local variable or a class member but theoretically it is even possible to declare a vector of auto_ptr<Type> because auto_ptr<Type> stores an ownership indicator and its copy constructor transfers the ownership from the instance being copied, so vector::push_back(…) and vector::resize(…) functions works correctly.

(more…)

How to implement WCF service in PHP

Today I implemented my first PHP Web Service and successfully used it by C# client or, more precisely, I created WCF service contract in C# and implemented it in PHP.  A new option “singlewsdl” in WCF 4.5  helped me a lot. Using this option I generated the service description as a single WSDL-file without additional XSD-files containing the data contracts of the service. Then I uploaded this WSDL-file on my Web Server and written PHP code for all the methods of the service.

(more…)

Integrating C# and PHP using XML-RPC and WCF

While investigating how to make C# and PHP interact with each other I run into an interesting extension of WCF Service Model for working over XML-RPC protocol. I played a bit with this extension and after fixing some bug in its source code I made it work with my little custom XML-RPC server implemented as Joomla XML-RPC plugin.

(more…)

How to specify WPF control size in millimeters using XAML

The first thing that we need to do to use millimeters in XAML is to define simple Mm2PixelConverter class that performs the conversion from millimeter to pixels:

[ValueConversion(typeof(double), typeof(double))]
class Mm2PixelConverter : IValueConverter
{
    #region IValueConverter Members

    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        double mm = (double)value;

        return WinUtil.Mm2Pixel(mm);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }

    #endregion
}

(more…)

Using ADO.NET Entity Framework with MySQL

In general, getting EF work with MySQL is a fairly simple task, that could be accomplished by downloading and installing ADO.NET driver for MySQL. But what concerns to me, it taken me about four hours to clarify some MySQL-specific details that affect generation of associations in Model Designer. Also after doing an experimentation with the code I realized that ADO.NET driver for MySQL, as well as other third party ADO.NET drivers, do not support “MARS” and, as far as I see, this significant restriction makes EF unusable with MySQL in large real-life projects. Please read below if you interested in more information on this questions.
(more…)

Seeing design time data in a WPF control

Sometimes the ability to see the data at design time significantly facilitates the creation of WPF controls. If I am developing a WPF control with complex UI using data bound controls, I usually define a property for accessing some typical data item:

public static ComplexData DesignTimeItem
{
    get
    {
        using (DatabaseContext db = new DatabaseContext())
        {
            var products = from p in db.products.Include("ProductType")
                           where p.product_id == 131
                           select p;

            product product = products.First();

            return new ComplexData(product, "100 kg");
        }
    }
}

(more…)