Finding the handle to a WPF window
Well, instead of passing Application.Current.MainWindow, just pass a reference to whichever window it is you want: new WindowInteropHelper(this).Handle and so on.
Well, instead of passing Application.Current.MainWindow, just pass a reference to whichever window it is you want: new WindowInteropHelper(this).Handle and so on.
The WebBrowser has a NavigateToString method that you can use to navigate to HTML content. If you want to be able to bind to it, you can create an attached property that can just call the method when the value changes: public static class BrowserBehavior { public static readonly DependencyProperty HtmlProperty = DependencyProperty.RegisterAttached( “Html”, typeof(string), … Read more
A DataTemplateSelector does not respond to PropertyChange notifications, so it doesn’t get re-evaluated when your properties change. The alternative I use is DataTriggers that changes the Template based on a property. For example, this will draw all TaskModel objects using a ContentControl, and the ContentControl.Template is based on the TaskStatus property of the TaskModel <DataTemplate … Read more
If you really want to do mvvm , try to forget “how can I add controls”. You don’t have to, just think about your viewmodels – WPF create the contols for you 🙂 In your case lets say we have a SearchViewModel and a SearchEntryViewmodel. public class SearchEntryViewmodel { //Properties for Binding to Combobox and … Read more
You can also use this great value converter Then you declare in XAML something like this: <local:BoolToStringConverter x:Key=”BooleanToStringConverter” FalseValue=”No” TrueValue=”Yes” /> And you can use it like this: <TextBlock Text=”{Binding Path=MyBoolValue, Converter={StaticResource BooleanToStringConverter}}” />
You should use the StringFormat on the Binding. You can use either standard string formats, or custom string formats: <TextBox Text=”{Binding Value, StringFormat=N2}” /> <TextBox Text=”{Binding Value, StringFormat={}{0:#,#.00}}” /> Note that the StringFormat only works when the target property is of type string. If you are trying to set something like a Content property (typeof(object)), … Read more
There are two techniques that might be a big help. Both of them are described very well by Bea Stolnitz on her blog. The first is UI Virtualization and the second is Data Virtualization In UI virtualization you use things like VirtualizingStackPanel to make the UI draw fewer things. Data virtualization makes sure you don’t … Read more
Your icon file should be added to one of your project assemblies and its Build Action should be set to Resource. After adding a reference to the assembly, you can create a NotifyIcon like this: System.Windows.Forms.NotifyIcon icon = new System.Windows.Forms.NotifyIcon(); Stream iconStream = Application.GetResourceStream( new Uri( “pack://application:,,,/YourReferencedAssembly;component/YourPossibleSubFolder/YourResourceFile.ico” )).Stream; icon.Icon = new System.Drawing.Icon( iconStream );
I did something simple, but it works. I used a typical ToggleButton, which I restyled as a textblock by changing its control template. Then I just bound the IsChecked property on the ToggleButton to the IsOpen property on the popup. Popup has some properties like StaysOpen that let you modify the closing behavior. The following … Read more
Transforming a known size to device pixels If your visual element is already attached to a PresentationSource (for example, it is part of a window that is visible on screen), the transform is found this way: var source = PresentationSource.FromVisual(element); Matrix transformToDevice = source.CompositionTarget.TransformToDevice; If not, use HwndSource to create a temporary hWnd: Matrix transformToDevice; … Read more