WIX bootstrapper application (BA) can easily determine if it runs as admin with the following code:
static bool IsAdmin()
WindowsIdentity id = WindowsIdentity.GetCurrent();
WindowsPrincipal principal = new WindowsPrincipal(id);
and if it does not, run a new instance as admin and exit:
static void RunAsAdmin()
ProcessStartInfo proc = new ProcessStartInfo
UseShellExecute = true,
WorkingDirectory = Environment.CurrentDirectory,
FileName = Process.GetCurrentProcess().MainModule.FileName,
Verb = "runas"
The existing ICollectionView implementations in WPF, for example ListCollectionView, work very good in trivial cases, they even can sort and filter the items from the underlying collection, but they have some significant disadvantage: they do not keep the correct sort order of an item and they do not filter the item out if its property is changed until ICollectionView.Refresh() method is called explicitly.
To overcome this inconvenience I developed my own implementation of ICollectionView interface that listens to all its items property change events via WeakEventManager and fires corresponding collection change events to re-soft or re-filter the item if needed. It was not a very simple task for me, and I even debugged WPF source code a bit and realized that it works a bit strange, for example, ItemsControl cannot work with my ICollectionView implementation directly, instead it creates some CollectionViewProxy that wraps it and uses some proxy enumerator to access an item by index:
Visual Studio 2013 allows easily to debug .NET 4.5.1 Framework source code. If you use a previous version of .NET (4.5 or earlier) change the target .NET version of the your projects to 4.5.1 or higher. If you have some C++ CLI projects modify TargetFrameworkVersion attribute manually in all *.vcxproj files:
then go to Tools->Options->Debugging->General and check/uncheck the following options:
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:
<ColumnDefinition Width="Auto" />
<Border Grid.Row="6" Grid.ColumnSpan="2" Visibility="Visible" Height="200">
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:
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)
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;
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:
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.
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.
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.
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:
class Mm2PixelConverter : IValueConverter
#region IValueConverter Members
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
double mm = (double)value;
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
throw new NotImplementedException();
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.