WPF Drag & drop from ListBox with SelectionMode Multiple

I’ve found a very simple way to enable Windows Explorer like drag/drop behaviour when having multiple items selected. The solution replaces the common ListBox with a little derived shim that replaces the ListBoxItem with a more intelligent version. This way, we can encapsulate the click state at the right level and call into the protected … Read more

How to make WPF input control show virtual Keyboard when it got focus in touch screen

Try this, First check for a physical keyboard presence: KeyboardCapabilities keyboardCapabilities = new Windows.Devices.Input.KeyboardCapabilities(); return keyboardCapabilities.KeyboardPresent != 0 ? true : false; If you do not find a physical keyboard, use the in-built virtual keyboard of windows: Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.System) + Path.DirectorySeparatorChar + “osk.exe”); Got help from here: link 1 link 2

Using MS ReportViewer in WPF

Yes, that works, I am using the WindowsFormsHost in a wpf project to wrap the ReportViewer. In the ViewModel I am creating the WindowsFormsHost and the ReportViewer: WindowsFormsHost windowsFormsHost = new WindowsFormsHost(); reportViewer = new ReportViewer(); windowsFormsHost.Child = reportViewer; this.Viewer = windowsFormsHost and in the View I am using a ContentPresenter to display it, by … Read more

How can WPF objects deriving from Freezable be frozen in XAML?

To freeze a Freezable object declared in markup, you use the Freeze attribute defined in XML namespace http://schemas.microsoft.com/winfx/2006/xaml/presentation/options. In the following example, a SolidColorBrush is declared as a page resource and frozen. It is then used to set the background of a button. <Page xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation” xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml” xmlns:po=”http://schemas.microsoft.com/winfx/2006/xaml/presentation/options” xmlns:mc=”http://schemas.openxmlformats.org/markup-compatibility/2006″ mc:Ignorable=”po”> <Page.Resources> <!– This brush is frozen … Read more

Creating WPF BitmapImage from MemoryStream png, gif

Add bi.CacheOption = BitmapCacheOption.OnLoad directly after your .BeginInit(): BitmapImage bi = new BitmapImage(); bi.BeginInit(); bi.CacheOption = BitmapCacheOption.OnLoad; … Without this, BitmapImage uses lazy initialization by default and stream will be closed by then. In first example you try to read image from possibly garbage-collected closed or even disposed MemoryStream. Second example uses file, which is … Read more

how to hide a button that is bound to a command that cannot execute?

You could use a Style and Triggers, assuming that the command is in charge of setting the Button enabled/disabled: <Button x:Name=”btnMoveUp” Command=”{x:Static local:Window1.MoveItemUp}”> <Button.Style> <Style TargetType=”{x:Type Button}” > <Style.Triggers> <Trigger Property=”IsEnabled” Value=”False”> <Setter Property=”Visibility” Value=”Collapsed” /> </Trigger> </Style.Triggers> </Style> </Button.Style> </Button> Note that you can define this Style at a higher scope and share it … Read more

Get owner of context menu in code

this will give you the exact thing you want private void OnDeleteClicked(object sender, System.Windows.RoutedEventArgs e) { MenuItem mnu = sender as MenuItem; StackPanel sp = null; if(mnu!=null) { sp = ((ContextMenu)mnu.Parent).PlacementTarget as StackPanel; } } Hope this helps!!