Search This Blog

Sunday, May 12, 2019

Set current date WPF calendar

WPF -> Calendar

calendar.DisplayDate = new DateTime(2020, 4, 17);
calendar.SelectedDate = new DateTime(2020, 4, 17);


Wednesday, May 8, 2019

WPF Calendar SelectedDates

WPF->Calendar

Add multiple selected dates to WPF Calendar.

<Grid>
   <Calendar x:Name="calendar" />

</Grid>

calendar.SelectionMode = CalendarSelectionMode.MultipleRange; 
calendar.SelectedDates.Add(new DateTime(2020, 1, 1)); 
calendar.SelectedDates.Add(new DateTime(2020, 1, 2));


Wednesday, December 5, 2018

WPF TabControl Example

WPF -> Controls -> TabControl 

WPF TabControl elements display content on discrete pages accessed by selecting the appropriate tab.

Example

<Window x:Class="Agenda.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"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <TabControl>
            <TabItem Header="Agenda">
            </TabItem>
            <TabItem Header="Cards">
            </TabItem>
        </TabControl>
    </Grid>
</Window>



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