Create a Behavior for Calendar in a WPF UserControl to Select and Unselect dates with one click

Hi to everyone,
I am developing an application with a WPF Client. This Client use the MVVM pattern.
In an UserControl the application must show some Calendars, so the user can select one or multiple dates.
For that use, I should implement some behavior that allows the user click once in a date and that date is selected (what already exists in .NET Framework) and with another click in the same date, that date is now unselected.
I've already made some searches and can't find anything useful.
This kind of behavior it is possible to implement in the Calendar Control? How exactly I do this?
Thanks for reading/helping
Rafael Duarte

You should be able to accomplish this by modifying the default template of the CalendarDayButtonStyle of the Calendar and handling the PreviewMouseLeftButtonDown of the Grid in the default template. Here is an example:
<Window.Resources>
<Style x:Key="CalendarDayButtonStyle1" TargetType="{x:Type CalendarDayButton}">
<Setter Property="MinWidth" Value="5"/>
<Setter Property="MinHeight" Value="5"/>
<Setter Property="FontSize" Value="10"/>
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type CalendarDayButton}">
<Grid Background="Transparent" PreviewMouseLeftButtonDown="Grid_PreviewMouseLeftButtonDown">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.1"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Normal"/>
<VisualState x:Name="MouseOver">
<Storyboard>
<DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<DoubleAnimation Duration="0" To="0.5" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Disabled">
<Storyboard>
<DoubleAnimation Duration="0" To="0" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="HighlightBackground"/>
<DoubleAnimation Duration="0" To=".35" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="NormalText"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="SelectionStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Unselected"/>
<VisualState x:Name="Selected">
<Storyboard>
<DoubleAnimation Duration="0" To=".75" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="SelectedBackground"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="CalendarButtonFocusStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<!--<VisualState x:Name="CalendarButtonFocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DayButtonFocusVisual">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Visible</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>-->
<!-- <VisualState x:Name="CalendarButtonUnfocused">
<Storyboard>
<ObjectAnimationUsingKeyFrames Duration="0" Storyboard.TargetProperty="Visibility" Storyboard.TargetName="DayButtonFocusVisual">
<DiscreteObjectKeyFrame KeyTime="0">
<DiscreteObjectKeyFrame.Value>
<Visibility>Collapsed</Visibility>
</DiscreteObjectKeyFrame.Value>
</DiscreteObjectKeyFrame>
</ObjectAnimationUsingKeyFrames>
</Storyboard>
</VisualState>-->
</VisualStateGroup>
<VisualStateGroup x:Name="ActiveStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="Active"/>
<VisualState x:Name="Inactive">
<Storyboard>
<ColorAnimation Duration="0" To="#FF777777" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="NormalText"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="DayStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="RegularDay"/>
<VisualState x:Name="Today">
<Storyboard>
<DoubleAnimation Duration="0" To="1" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="TodayBackground"/>
<ColorAnimation Duration="0" To="#FFFFFFFF" Storyboard.TargetProperty="(TextElement.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="NormalText"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
<VisualStateGroup x:Name="BlackoutDayStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0"/>
</VisualStateGroup.Transitions>
<VisualState x:Name="NormalDay"/>
<VisualState x:Name="BlackoutDay">
<Storyboard>
<DoubleAnimation Duration="0" To=".2" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Blackout"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="TodayBackground" Fill="#FFAAAAAA" Opacity="0" RadiusY="1" RadiusX="1"/>
<Rectangle x:Name="SelectedBackground" Fill="#FFBADDE9" Opacity="0" RadiusY="1" RadiusX="1"/>
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"/>
<Rectangle x:Name="HighlightBackground" Fill="#FFBADDE9" Opacity="0" RadiusY="1" RadiusX="1"/>
<ContentPresenter x:Name="NormalText" TextElement.Foreground="#FF333333" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="5,1,5,1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
<Path x:Name="Blackout" Data="M8.1772461,11.029181 L10.433105,11.029181 L11.700684,12.801641 L12.973633,11.029181 L15.191895,11.029181 L12.844727,13.999395 L15.21875,17.060919 L12.962891,17.060919 L11.673828,15.256231 L10.352539,17.060919 L8.1396484,17.060919 L10.519043,14.042364 z" Fill="#FF000000" HorizontalAlignment="Stretch" Margin="3" Opacity="0" RenderTransformOrigin="0.5,0.5" Stretch="Fill" VerticalAlignment="Stretch"/>
<Rectangle x:Name="DayButtonFocusVisual" IsHitTestVisible="false" RadiusY="1" RadiusX="1" Stroke="#FF45D6FA" Visibility="Collapsed"/>
</Grid>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsSelected" Value="True"/>
<Condition Property="IsFocused" Value="True"/>
</MultiTrigger.Conditions>
<Setter Property="Visibility" TargetName="DayButtonFocusVisual" Value="Visible"/>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Calendar x:Name="cal" CalendarDayButtonStyle="{DynamicResource CalendarDayButtonStyle1}" />
private void Grid_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e) {
Grid grid = sender as Grid;
CalendarDayButton button = FindParent<CalendarDayButton>(grid);
if (button.IsSelected) {
Calendar cal = FindParent<Calendar>(button);
if (cal.SelectedDate.HasValue) {
cal.SelectedDates.Remove(cal.SelectedDate.Value);
e.Handled = true;
Hope that helps.
Please remember to mark helpful posts as answer and/or helpful.

Similar Messages

  • How to create apple id for mac app store without using credit card and there is no any option for payment none. please tell how to download free apps from mac app store

    how to create apple id for mac app store without using credit card and there is no any option for payment none. please tell how to download free apps from mac app store

    my problem solve by me
    first create apple id
    fill credit card details
    and complete your account creating  process.
    than go to app store or itune store
    login your acount
    click right side  - account button
    than again login for account setting
    next go to payment information and click edit button
    when u enter payment infomation
    click none button in payment method and click done button.
    than ur credit card has been removed.
    but rs. 60 will deducted in your account when u doing this process.

  • HT204150 I have only 2 choices for contact groups on the iPhone 5, hotmail and iCloud. If I click both then I have all my hotmail contacts which I don't want. However if I only click iCloud, any new contacts I add don't show up :(

    I have only 2 choices for contact groups on the iPhone 5, hotmail and iCloud. If I click both then I have all my hotmail contacts which I don't want. However if I only click iCloud, any new contacts I add don't show up

    Only contacts added to the iCloud group will sync with iCloud.  To make this your default, go to Settings>Mail,Contacts,Calendars...scroll down to the Contacts section and tap Default Account.  Here, choose iCloud as your default.  After doing so, new contacts will be added to iCloud and sync with your iCloud account.

  • Am I able to tag a data point of a spreadsheet that is being created by a datalogging VI such that at the end I have the data with multiple tags which corelate to events during a measurement cycle

    Am I able to tag a data point of a spreadsheet that is being created by a datalogging VI such that at the end I have the data with multiple tags which corelate to events during a measurement cycle
    My final need is to take data from a datalogging VI and store it in a spreadsheet with tags that corespond to events in a subVI which is controlling motor movement. This will allow users to view all data and mark the relevent data for analysis. As usual, user want everthing but with conditions.

    Sure. What you do is take the numeric value acquired, the tags you want, and build them into an array. So now, when you write to the spreadsheet, you'll have a 2D array. One thing you have to keep in mind is that all elements of an array have to be of the same type. So if your tags are strings, you'll have to convert your numeric data into strings as well.

  • How does schedule with RESTful API a Webi report for a group of users ("Schedule For" to "Schedule for specified users and user groups" with one or more users/groups)?

    SAB BO 4.1 SP1
    Does it have an RESTful API to schedule a Webi report with the parameter to specify a group of users ("Schedule For" to "Schedule for specified users and user groups" with one or more users/groups)?

    Hello Ricardo,
    have you try a call like this one ?
        <schedule>
          <name>"test"</name>"
          <format type=\"webi\"/>
          <destination>
            <inbox>
             <to>userId1,userId2,userId3,groupId1,groupId12</to>
            </inbox>
          </destination>
        </schedule>
    Regards
    Stephane

  • With one click, can one upload an entire folder containing at least 7GB of Excel spreadsheet to ICloud and then be able to view them on an Ipad using Numbers. Also, would this cause one to have to pay for over 5GB of space?

    Want to travel only with my Ipad.  Would like to easily upload, with one click, large 7GB folders of both Excel spreadsheets and Word documents to ICloud and then be able to view, change and create individual spreadsheets and documents using Numbers and Pages on my Ipad through the internet? Also, this would exceed the 5GB offered free, but someone said if I am only syncing and not backing up there would be no charge.  Please explain.

    You can't
    Pages and Numbers can save to iCloud, Word and Excel can not.

  • Blue screen on start up.  The wheel spin and the blue screen gets brighter for a second, then the blue screen dims and it repeats with the wheel.

    When I start up my imac, I get a blue screen.  The wheel spin and the screen gets brighter for a second, then the blue screen dims and it repeats with the wheel.

    Are you referring to the startup screen which is normally gray with the dark gray Apple logo or are you referring the login screen which is typically blue? If it's the latter you might give this a try:
    Clearing Caches to Fix Login Problem
    You will need to type some Unix commands. If you are not comfortable with this, I don't know of anything other than a re-install. But if you are careful, you should be OK. I recommend you print this out in a largish mono-spaced font so you don't miss any spaces (or add extra ones). Note that case is important.
    Be careful. Some of these commands are dangerous, since you are going to be root.
    Start up in Single-user Mode. When this has finished you will see a prompt ending in '#', although there may be other messages. Enter the following commands after the prompt:
    /sbin/fsck -fy
    Press RETURN. Wait a few seconds for 8-10 lines of output. If the last line says repairs were carried out, repeat this command until you get a message 'The volume <yourdiskname> appears to be OK'. Then continue with:
    /sbin/mount -uw /
    cd /Library/Preferences
    rm com.apple.loginwindow.plist
    rm com.apple.windowserver.plist
    cd /Library/Caches
    rm -r *
    cd /System/Library
    cd /System/Library/Caches
    rm -r *
    reboot
    Press RETURN after each command.
    This should now take you to a proper login screen after the normal boot sequence. You should then Repair Permissions by using Disk Utility (in your /Applications/Utilities folder).
    If it's the former then reinstall OS X. For Snow Leopard:
    Reinstall OS X without erasing the drive
    Do the following:
    1. Repair the Hard Drive and Permissions
    Boot from your Snow Leopard Installer disc. After the installer loads select your language and click on the Continue button. When the menu bar appears select Disk Utility from the Utilities menu. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the installer.
    If DU reports errors it cannot fix, then you will need Disk Warrior and/or Tech Tool Pro to repair the drive. If you don't have either of them or if neither of them can fix the drive, then you will need to reformat the drive and reinstall OS X.
    2. Reinstall Snow Leopard
    If the drive is OK then quit DU and return to the installer.  Proceed with reinstalling OS X.  Note that the Snow Leopard installer will not erase your drive or disturb your files.  After installing a fresh copy of OS X the installer will move your Home folder, third-party applications, support items, and network preferences into the newly installed system.
    Download and install the Combo Updater for the version you prefer from support.apple.com/downloads/.

  • Create multiple folders with one click on documents tab in BP in SAP CRM

    Hi Experts,
    I have a requirement to create multiple folders by clicking on a button in Documents tab in BP transaction in CRM. In standard process by clicking on create folder button we create folders. we want to create multiple folders with one single click ( i guess we can develop another button for that) folder name will be hard coded. Kindly let me know , how this can be achieved.

    Hi Experts,
    I have a requirement to create multiple folders by clicking on a button in Documents tab in BP transaction in CRM. In standard process by clicking on create folder button we create folders. we want to create multiple folders with one single click ( i guess we can develop another button for that) folder name will be hard coded. Kindly let me know , how this can be achieved.

  • Is there a way to add multiple borders to a single cell with one click or do I have to add one border at a time for example, one cell with borders on three sides?

    I would like to know if there is a way to add multiple borders to a single cell or selection of cells in one click.  At this time, if i want to add for example a top border and a bottom border to a single cell I have to do this in two steps: first select the top border, style, thickness, and color, and then next select the bottom border, style, thickness, and color.  Is there a way to select the top and bottom border of a cell in one click?  Clicking on the top border then holding down the command key while selecting the bottom border does not work, nor does holding down the option key, the control key, or the shift key work. Thanks for your help.

    Thank you for the suggestion but this did not work for my Mac.  When a cell is selected for which I want borders, the entire cell is lit up.  Then when I go to the border tool and select style, thickness, and color, the entire lit up cell takes on the border, that is the Outside Edges of the cell now have a border.  So selecting the style, thickness, and color first doesn't work.
    If I select the top border first (or any border), the drop down goes away and I can't select multiple borders - I get to choose one at a time.  After selecting one border, style, thickness, and color, said border is now on the spreadsheet.  Then I go back to the border selection and pick another border and the the previously selected style, thickness, and color reverts to null, so I start over with the new border style, thickness, and color.  Yes, it is tedious.
    The Fix would allow the user to select multiple borders, say left and right, before the drop down goes away after selecting only one border
    Does it have something to do with Allow or Disallow border selection?
    I have Numbers '09 version 2.1 (436)

  • Looking for a browser or app with one click data entry

    One thing I miss on the iPad is the ability to quickly enter information in web sites like my name, e-mail, etc. For example, Firefox for windows has an add-on called "InFormEnter" which places a check box next to each data entry block. Clicking on it allows entry of the information with one additional click. I know that some iPad password managers will remember this info, but most seem to require entering a password each time you use it.
    Mercury browser for the iPad remembers data for visited sites but seems to require manual input for every new site.
    Is there an app or browser for iPad that will work without entering a password or requiring manual input for every new site?

    The subscription version of LastPass has formfill capability and syncs information from your LastPass account that works on multiple platforms/OSs.

  • How do I create a form that will give a report that summarises before and after data on the same graph?

    I have a number questions that I want to know the average of all the before and after data to compare them, how do I set this up in a form in FormsCentral?  Here is an example of what I want to do - the green bar is "before" and blue is "after"

    This isn't something that you can set up in FormsCentral. It's possible to something similar with a form you create in Acrobat and use with FormsCentral, but there is no sort of built-in graphing control. The bar graph could be implemented with some JavaScript that controls annotations or fields (buttons) and perhaps some text fields.

  • Creation of Z reports for client adding two more column that is Purcahse order and delivery dates with Internal order wise

    HI Experts,
    Can any one help me to add two more column for standard report that is purchase order and delivery dates for Internal order wise.
    But here problem is when i checked with ABAP team they said there is no standard functional module to add two column.
    Please note below :
    Selection criteria is: 1) controlling area
                                  2) Fiscal Year
                                  3) From date and To date
                                  4) Plan Version
                                  5) Order Group.
    My client suggested : S_ALR_87012993 this tcode to run, but we suggested with S_ALR_87013019 as in this tcode we can get all the details
    That is required output fields, as it is showing all details but on yearly basis, he wants this to be period wise and also Abap team is not able to find standard functional module in the second tcode as well.
    Out Put fields to Pop up
    1) Orders.
    2) Budget
    3) Actual
    4) commitment
    5) Alloted
    6) Available
    These are two additional column
    7)Purchase order
    8) Delivery date.
    Require your help to know which all tables are included to extract above out put fields please help me.
    Thanks in Advance.
    Regards,
    Sudesh

    Hi Preeti,
    Thanks for reply, can you please let me know is there any other way to show the output fields.
    As my client is very specific to run the report on period wise, i also tried to execute the standard tcode S_ALR_87013019 and were we are getting all the required outputs to pop up but this is on year wise, but we can also check by period basis by clicking on order number and actual period basis where we can see period basis.
    Also one more question,what is the commitment table which is popping up in this, please advise.
    Thanks in advance.
    Regards,
    Sudesh

  • I have logic pro studio 8 and the upgrade, however it will not upload on my mac book pro. It says i need a product key for the logic 9 and it come with one.

    I have logic pro studio 8 and the upgrade (logic pro 9) and it will not load up to my new mac book pro.  Its asking for a product key for the logic pro 9 upgrade and there wasn't one in the box.  i need some help

    Contact AppleCare... Explain you are a Logic User and you should be transfered to a Product Specialist to assist you with your Issue.

  • How to create URL link for telephone number ,open to account search page and account result page ?

    Hi Experts,
    Bussines role - ZCC_ICAGENT 
    If user open this bussiness role and open Account page ,user enter telephone number and enter search account ,then result will be displayed.Instead of 3 clicks ,user click direct URL link ,telephone number is parameter,account Search and account result  page will be opened direct link.
    So how to do it..could you please provide me step by step...what are the steps wee need to follow for creating URL ..how to do it..Please help..
    Thanks
    Kalpana

    Hi kalpana,
    You dont need to do any setting for this.
    Following URL will be used as per your requirement.
    http://rrnewcrm.ril.com:8000/sap(bD1lbiZjPTI0MiZkPW1pbg==)/bc/bsp/sap/crm_ui_start/default.htm
    ?sap-system-login-basic_auth=X&sap-system-login=onSessionQuery&saprole=ZCC_ICAGENT&
    sap-phoneno=9999999999
    Here parameter sap-phoneno will contain the number you want to search for.
    In component ICCMP_BP_SEARCH, go to view BuPaSearchB2B. write below code in its inbound plug IP_INBOUNDPLUG-
    DATA: lt_ivr_url_param TYPE tihttpnvp,
             ls_ivr_url_param TYPE ihttpnvp,
             lr_searchcustomer TYPE REF TO if_bol_bo_property_access,
             ls_searchcustomer TYPE crmt_bupa_il_header_search.
    CALL METHOD cl_crm_ui_session_manager=>get_initial_form_fields
           CHANGING
             cv_fields = lt_ivr_url_param.
    lr_searchcustomer ?= me->typed_context->searchcustomer->collection_wrapper->get_current( ).
         CHECK lr_searchcustomer IS BOUND.
    READ TABLE lt_ivr_url_param INTO ls_ivr_url_param WITH KEY name = 'sap-phoneno'.
    IF ls_ivr_url_param-value IS NOT INITIAL.
             ls_searchcustomer-telephone = ls_ivr_url_param-value.
       CALL METHOD lr_searchcustomer->set_properties( EXPORTING is_attributes = ls_searchcustomer ).
             eh_onsearch( ).
        ENDIF.
    Thanks & Regards
    Richa

  • 4 devices linked to 1 itunes acct.  how do i create an account for each device but keep the music/apps purchased to date

    2 ipod touches, 1 iphone, 1 ipad all linked to the same itunes account.  would like to know if there is a way to have 3 seperate accounts and still keep the music/apps purchased to date.  1 ipod has been lost....how do I delete it from the itunes account.  Is homesharing something that i can use for this situation?
    any help is much appreciated!

    You cannot

Maybe you are looking for

  • Openbox and urxvt(solved)

    I have two questions.First,how can i start urxvt when openbox starts.If i put urxvt in autostart.sh,it starts at up left corner,and i can't type anything,i must kill it.When i start urxvt normaly, it starts at down left corner because of rc.xml setin

  • Ipad2 no longer able to share imac's ethernet via internet sharing.

    Worked flawlessly up to about 30 ft before. Immdiate hook up when in range. Have tried a lot of things to no avail. Something is interfering. Any ideas?

  • ChaRM: usage of ChaRM and none-Charm transport strategy

    Hi ChaRM-TMS Gurus! We have the following [SAP system landscape |http://www.file-upload.net/view-1086963/SDN_TMS_Ist_Soll.jpg.html] and would like to use ChaRM approach simultaneously. What are the minimal requirements concerning transport layers/rou

  • D'oh. looking for a pdf.

    I have a 500+ page jsp pdf file at home made by sun. I was suppose to bring it with me today, but i forgot. I looked in the tutorial section, but most of them seem to be only be 125 or so pages. I think the books title was "developing in jsp". anyone

  • Unknown Error When Trying to Send & Collaborate Live

    When I try to share a file using Send & Collaborate Live, I get "an unknown error has occurred" in Acrobat while trying to share a document. I get another message after closing out the error message dialog box that tells me Acrobat "could not save th