Search This Blog

Friday, October 26, 2018

DatePicker WPF Example

System.Windows.Controls -> DatePicker

Represents a control that allows the user to select a date.

Example


<Window x:Class="WpfApp4.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <Grid>
        <DatePicker HorizontalAlignment="Left" Margin="225,118,0,0" VerticalAlignment="Top" SelectedDateChanged="DatePicker_SelectedDateChanged"/>
    </Grid>
</Window>

private void DatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
  var datePicker = sender as DatePicker;
  MessageBox.Show(datePicker.SelectedDate.ToString());
}

Tuesday, August 22, 2017

Display XAML window in the second display WPF

WPF > Windows > Forms > Screen

AllScreens gets an array of all displays on the system.

Example

Display window in the second display WPF

private void Window_Loaded(object sender, RoutedEventArgs e)
{
   var screen = System.Windows.Forms.Screen.AllScreens.Where(s => !s.Primary).First();
   var area = screen.WorkingArea;
   Left = area.Left;
   Top = area.Top;
   Width = area.Width;
   Height = area.Height;
}

Wednesday, July 26, 2017

GridViewColumnHeader WPF Example

WPF > Controls  > ContentControl > GridViewColumnHeader

GridViewColumnHeader object is a button control that is derived from ButtonBase. 
Column headers in a GridView view mode are GridViewColumnHeader objects.
Example

<Window x:Class="GridViewColumnHeader.MainWindow"
        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"
        xmlns:local="clr-namespace:GridViewColumnHeader"
        mc:Ignorable="d"
        Title="MainWindow" Height="350" Width="525">
    <Grid>
        <ListView>
            <ListView.View>
                <GridView>
                    <GridViewColumn>
                        <GridViewColumnHeader>Name
                            <GridViewColumnHeader.ContextMenu>
                                <ContextMenu>
                                    <MenuItem Header="Ascending" />
                                    <MenuItem Header="Descending" />
                                </ContextMenu>
                            </GridViewColumnHeader.ContextMenu>
                        </GridViewColumnHeader>
                    </GridViewColumn>
                </GridView>
            </ListView.View>
        </ListView>
    </Grid>
</Window>



Wednesday, July 12, 2017

Get Vertical ScrollBar Width WPF

WPF > Windows > SystemParameters > VerticalScrollBarWidth


This value indicates the width (in pixels) of a vertical scroll bar.

SystemParameters.VerticalScrollBarWidth

WPF SystemParameters Class

WPF > Windows > SystemParameters


Thursday, May 4, 2017

Bind Width to another Width control WPF

WPF > Binding > Width

<Grid>
  <Grid.ColumnDefinitions>
    <ColumnDefinition 
Width="{Binding ElementName=controlName, Path=ActualWidth}"/>
  </Grid.ColumnDefinitions>

Monday, March 13, 2017

ScrollToTop DataGrid WPF

WPF> DataGrid > Scroll To Top


var border = VisualTreeHelper.GetChild(myDataGrid, 0) as Decorator;
if (border != null && border.Child !=null)
{
  var scrollViewer = border.Child as ScrollViewer;
  if (scrollViewer != null)
  {
    scrollViewer.ScrollToTop();
  }

}