Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Thursday, June 28, 2012

ToolTips in WPF

ToolTips in WPF

 
<Button Content="Submit">
    <Button.ToolTip>
        <ToolTip>
            <StackPanel>
                <TextBlock FontWeight="Bold">Submit Request</TextBlock>
                <TextBlock>Submits the request to the server.</TextBlock>
            </StackPanel>
        </ToolTip>
    </Button.ToolTip>
</Button>
 
 

How to show ToolTips on disabled controls

When you disable a control with IsEnabled=False the tooltip does not show anymore. If you want to have the tooltip appear anyway you have to set the attaached property ToolTipService.ShowOnDisabled to True.
 
<Button IsEnabled="False" 
        ToolTip="Saves the current document"
        ToolTipService.ShowOnDisabled="True"
        Content="Save">
</Button>
 
 

How to change the show duration of a ToolTip

The static class ToolTipService allows you to modify the show duration of the tooltip
 
<Button ToolTip="Saves the current document"
        ToolTipService.ShowDuration="20"
        Content="Save">
</Button>

WPF Calendar Control

Introduction

Since WPF 4.0, Microsoft provides a full featured calendar control. It provides the following features:

Set the displayed date

The calendar displays by default the current date. But you can specify any other date to be displayed by setting the DisplayDate property.
 
<Calendar DisplayDate="01.01.2010" />
 
 

Selection Modes

The calendar control provides multiple modes for selection. You can set the SelectionMode property to SingleDateSingleRange, MultipleRanges or None.
 
<Calendar SelectionMode="MultipleRange" />
 
 

Blackout dates

The calendar control provides a feature to black out dates that are not valid for selection. You can define multiple ranges by setting the BlackoutDates property to one or multiple CalendarDateRange.
 
<Calendar SelectionMode="{Binding SelectedItem, ElementName=selectionmode}" >
    <Calendar.BlackoutDates>
        <CalendarDateRange Start="01/01/2010" End="01/06/2010" />
        <CalendarDateRange Start="05/01/2010" End="05/03/2010" />
    </Calendar.BlackoutDates>
</Calendar>
 
 

Calendar Modes

The calendar supports three modes to display ranges of dates: Year, Month and Decade. You can control the mode by setting the DisplayMode property.
 
<Calendar DisplayMode="Year" />

ComboBox with Live Preview

ComboBox with Live Preview

The Live Preview Pattern

If you are using Microsoft Office 2007 or later, you are familiar with the "live preview" concept. They are using it for all kind of selections like color, fonttype or fontsize. The idea behind this pattern is to give the user an immediate feedback, how the object would look like, if he does the selection, without actually doing it. So he can leave the combo and nothing has changed.

How to use the LivePreviewComboBox Control

I encapsulated this functionality into a custom control called LivePreviewComboBox that provides an additional dependency property LivePreviewItem where you can bind to. The following code snipped explains how to use it:
 
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:l="clr-namespace:LivePreviewComboBox">
 
    <StackPanel>
        <TextBlock Text="Preview Value:" />
        <TextBlock Text="{Binding LivePreviewItem, ElementName=liveBox}" />
        <l:LivePreviewComboBox x:Name="liveBox"/>
    </StackPanel>
 
</Window>

ItemsControl

How to automatically scroll to the last item

 
<ListBox l:ItemsControlHelper.ScrollToLastItem="true" />
 
 


 
public static class ItemsControlHelper
{
    public static readonly DependencyProperty ScrollToLastItemProperty =
        DependencyProperty.RegisterAttached("ScrollToLastItem",
            typeof(bool), typeof(ItemsControlHelper),
            new FrameworkPropertyMetadata(false, OnScrollToLastItemChanged));
 
    public static void SetScrollToLastItem(UIElement sender, bool value)
    {
        sender.SetValue(ScrollToLastItemProperty, value);
    }
 
    public static bool GetScrollToLastItem(UIElement sender)
    {
        return (bool)sender.GetValue(ScrollToLastItemProperty);
    }
 
    private static void OnScrollToLastItemChanged(DependencyObject sender, 
                            DependencyPropertyChangedEventArgs e)
    {
        var itemsControl = sender as ItemsControl;
 
        if (itemsControl != null)
        {
            itemsControl.ItemContainerGenerator.StatusChanged += 
                     (s,a) => OnItemsChanged(itemsControl,s,a);
        }
    }
 
    static void OnItemsChanged(ItemsControl itemsControl, object sender, EventArgs e)
    {
        var generator = sender as ItemContainerGenerator;
        if( generator.Status == GeneratorStatus.ContainersGenerated )
        {
            if (itemsControl.Items.Count > 0)
            {
                ScrollIntoView(itemsControl, 
                 itemsControl.Items[itemsControl.Items.Count - 1]);
            }
        }
    }
 
    private static void ScrollIntoView(ItemsControl itemsControl, object item)
    {
        if (itemsControl.ItemContainerGenerator.Status == 
            GeneratorStatus.ContainersGenerated)
        {
            OnBringItemIntoView(itemsControl, item);
        }
        else
        {
            Func<object, object> onBringIntoView = 
                    (o) => OnBringItemIntoView(itemsControl, item);
            itemsControl.Dispatcher.BeginInvoke(DispatcherPriority.Loaded, 
                  new DispatcherOperationCallback(onBringIntoView));
        } 
    }
 
    private static object OnBringItemIntoView(ItemsControl itemsControl, object item)
    {
        var element = itemsControl.ItemContainerGenerator.
                 ContainerFromItem(item) as FrameworkElement;
        if (element != null)
        {
            element.BringIntoView();
        }
        return null;
    }
}

WPF - Third Party Controls(Controls)

WPF Component Vendors


Bar Code

Data Grids

CAD

Charts

Color Picker

Diagram Editors

Dialogs and Windows

Dock

Editors

Effects

GIS and Maps

Multimedia

Misc

Office Components

Outlook Bar

Panels

Progress Bars

Property Grids

Reporting

Ribbon

Schedule

Slider

Toolbar

Theming

Tree

Web Browser

Wizard

3D

Tuesday, June 12, 2012

How to highlight Today's Date in ASP.NET AJAX Calender Extender

Here is a simple way to highlight Today's Date in ASP.NET AJAX Calender Extender using JavaScript.

Code for .aspx page:

<asp:TextBox ID="DateTextBox" runat="server"  />
<asp:Image ID="Image1" runat="server" ImageUrl="Calendar_scheduleHS.png" />
<ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="DateTextBox" PopupButtonID="Image1" OnClientShowing="CurrentDateShowing">
</ajaxToolkit:CalendarExtender>

Here's the JavaScript:

<script type="text/javascript">
function CurrentDateShowing(e)
{
      if (!e.get_selectedDate() || !e.get_element().value)

      e._selectedDate = (new Date()).getDateOnly();
}    
</script>

That's it !!!!

Now try to run the page (view page in browser) - Once you click on calender image button, you would see Today’s date is highlighted.

CalendarExtender Not working with Chrome

remove this line<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

add this line
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"></ajaxToolkit:ToolkitScriptManager>