Showing posts with label wpf. Show all posts
Showing posts with label wpf. Show all posts
Wednesday, May 11, 2016
Tuesday, August 11, 2015
WPF: How to remove icon from window caption
1. Add the following line to your window constructor:
2. Add this helper class to your project (find the latest version in GitHub):
namespace Vurdalakov
{
using System.Windows;
public partial class AboutWindow : Window
{
public AboutWindow()
{
InitializeComponent();
this.SourceInitialized += WindowHelper.RemoveIcon; // add this line
}
}
}
2. Add this helper class to your project (find the latest version in GitHub):
namespace Vurdalakov
{
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
public static class WindowHelper
{
public static void RemoveIcon(Window window)
{
if (null == window)
{
return;
}
var hWnd = new WindowInteropHelper(window).Handle;
var exStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
SetWindowLong(hWnd, GWL_EXSTYLE, exStyle | WS_EX_DLGMODALFRAME);
SendMessage(hWnd, WM_SETICON, IntPtr.Zero, IntPtr.Zero);
SendMessage(hWnd, WM_SETICON, new IntPtr(1), IntPtr.Zero);
SetWindowPos(hWnd, IntPtr.Zero, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_FRAMECHANGED);
}
public static void RemoveIcon(Object sender, EventArgs e)
{
RemoveIcon(sender as Window);
}
const Int32 GWL_EXSTYLE = -20;
const Int32 WS_EX_DLGMODALFRAME = 0x0001;
const Int32 SWP_NOSIZE = 0x0001;
const Int32 SWP_NOMOVE = 0x0002;
const Int32 SWP_NOZORDER = 0x0004;
const Int32 SWP_NOACTIVATE = 0x0010;
const Int32 SWP_FRAMECHANGED = 0x0020;
const UInt32 WM_SETICON = 0x0080;
[DllImport("user32.dll", SetLastError = true)]
static extern Int32 GetWindowLong(IntPtr hWnd, Int32 nIndex);
[DllImport("user32.dll", SetLastError = true)]
static extern Int32 SetWindowLong(IntPtr hWnd, Int32 nIndex, Int32 dwNewLong);
[DllImport("user32.dll", SetLastError = true)]
static extern Boolean SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, Int32 x, Int32 y, Int32 cx, Int32 cy, UInt32 uFlags);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
}
}
WPF: How to remove maximize and minimize buttons from a window
1. No need to keep the window resizable (dialog box):
2. If you want to keep the window resizable:
<Window x:Class="Vurdalakov.AboutWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Title="About" Height="200" Width="300"
ResizeMode="NoResize">
2. If you want to keep the window resizable:
namespace Vurdalakov
{
using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
public partial class MyWindow : Window
{
public MyWindow()
{
InitializeComponent();
this.SourceInitialized += (s, e) =>
{
var handle = new WindowInteropHelper(s as Window).Handle;
var style = GetWindowLong(handle, GWL_STYLE);
SetWindowLong(handle, GWL_STYLE, (int)(style & ~(WS_MAXIMIZEBOX | WS_MINIMIZEBOX)));
};
}
private const Int32 GWL_STYLE = -16;
private const Int32 WS_MAXIMIZEBOX = 0x10000;
private const Int32 WS_MINIMIZEBOX = 0x20000;
[DllImport("user32.dll")]
private static extern Int32 GetWindowLong(IntPtr hWnd, Int32 nIndex);
[DllImport("user32.dll")]
private static extern Int32 SetWindowLong(IntPtr hWnd, Int32 nIndex, Int32 dwNewLong);
}
}
WPF: How to hide the header of a listview
Just add the following style with GridView.ColumnHeaderContainerStyle tag to your XAML:
<ListView ...>
<ListView.View>
<GridView>
...
<GridView.ColumnHeaderContainerStyle>
<Style>
<Setter Property="FrameworkElement.Visibility" Value="Collapsed" />
</Style>
</GridView.ColumnHeaderContainerStyle>
...
</GridViewColumn>
</ListView.View>
</ListView>
Friday, June 28, 2013
Fast AddRange method for ObservableCollection
public class ObservableCollectionEx : ObservableCollection
{
public void AddRange(IEnumerable<T> list)
{
foreach (T item in list)
{
this.Items.Add(item);
}
this.OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
}
public void ClearAndAddRange(IEnumerable<T> list)
{
this.Items.Clear();
this.AddRange(list);
}
}
Labels:
wpf
Monday, May 6, 2013
Culture-specific sorting of CollectionViewSource using SortDescription
Just set Culture property of CollectionViewSource:
public CollectionViewSource All { get, private set; }
...
this.All = new CollectionViewSource();
this.All.Culture = new CultureInfo("fi-FI");
...
this.All.Source = this.items;
this.All.View.SortDescriptions.Add(new SortDescription("Name", ListSortDirection.Ascending));
Subscribe to:
Posts (Atom)