Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DataGrid DataGridTemplateColumn CalendarDatePicker and DatePicker Flash Then Desappear! #2493

Closed
maxmin88 opened this issue Sep 22, 2018 · 18 comments · Fixed by #4206
Closed
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Completed 🔥 DataGrid 🔠 Issues on DataGrid control
Milestone

Comments

@maxmin88
Copy link

I'm submitting a...

Bug report (I searched for similar issues and did not find one)

Current behavior

In a DataGridTemplateColumn with a CalendarDatePicker as the template when clicking on the date or icon the calendar picker flashes and then disappears. This is the same for CalendarDatePicker and DatePicker. Also the same result if CellTemplate or CellEditTemplate is used.

See code example below.

Expected behavior

Should be able to click on the date or the calendar icon and the calendar grid or date picker should open and stay open until the date is selected. The resulting date selected should be displayed in the date view.

Minimal reproduction of the problem with instructions

Please see example code below.

Environment

Nuget Package(s): 
Microsoft.Toolkit.Uwp.UI.Controls.DataGrid
Package Version(s): 
4.0

Windows 10 Build Number:
- [ ] Creators Update (15063)
- [ ] Fall Creators Update (16299)
- [x ] April 2018 Update (17134)
- [ ] Insider Build (build number: )

App min and target version:
- [ ] Creators Update (15063)
- [ min] Fall Creators Update (16299)
- [ target ] April 2018 Update (17134)
- [ ] Insider Build (xxxxx)

Device form factor:
- [X ] Desktop
- [ ] Mobile
- [ ] Xbox
- [ ] Surface Hub
- [ ] IoT

Visual Studio 
- [ X] 2017 (version: 15.8.4 )
- [ ] 2017 Preview (version: )

<UserControl.Resources> <DataTemplate x:Key="CalendarCell"> <TextBlock Text="{Binding DateCreated}"/> </DataTemplate> <DataTemplate x:Key="CalendarCellEdit"> <CalendarDatePicker Date="{Binding DateCreated}" /> </DataTemplate> </UserControl.Resources>

<dg:DataGrid x:Name="grdNotes" > <dg:DataGrid.Columns> <dg:DataGridTemplateColumn CellTemplate="{StaticResource CalendarCell}" CellEditingTemplate="CalendarCellEdit"/> </dg:DataGrid.Columns> </dg:DataGrid>

@lucaasrojas
Copy link
Contributor

Can you provide a reproduction project?

@kbrons kbrons added bug 🐛 An unexpected issue that highlights incorrect behavior DataGrid 🔠 Issues on DataGrid control labels Sep 24, 2018
@maxmin88
Copy link
Author

DataGridCalendarPickerTemplateBug.zip
OK. Here is a sample project showing the problem. I have tried options such as a single CalendarDatePicker in just the CellTemplate (no CellEditTemplate) and also the DatePicker and the results are the same.

And, I also just noticed, that the CalenderDatePicker is not getting it's Date set with the Binding to the CreatedDate field.

I also put a CalendarDatePicker directly on the page to show normal operation.

Hopefully there is a solution to this.

Thanks.

@RBrid
Copy link
Contributor

RBrid commented Sep 27, 2018

I don't have an explanation for the flashing issue yet - I suspect it's a focus problem. The CalendarDatePicker's drop-down must be losing focus right away.

As for the second part, i.e. the binding not working: make sure you bind the CalendarDatePicker.Date property to a DateTimeOffset. In my test scenario, I have a Person object with a DateOfBirth DateTime property, and I can bind to the Person.DateOfBirthOffset property which is defined as:

public class Person
{
...
public DataTimeOffset DateOfBirthOffset
{
get { return new DateTimeOffset(this.DateOfBirth); }
set { this.DateOfBirth = value.DateTime;
}
}

@edd2000uk
Copy link

Did you find any solution to this, I have the same problem with the CalendarDatePicker flashing up then disappearing. However if I select the picker on a different row it works. It seems that I can select a picker for the first time, then if I try to reselect it has the problem. If I select a picker on a new row then it works.

@lucaasrojas
Copy link
Contributor

@RBrid what is the current status?

@windowstoolkitbot
Copy link

This issue seems inactive. It will automatically be closed in 14 days if there is no activity.

2 similar comments
@windowstoolkitbot
Copy link

This issue seems inactive. It will automatically be closed in 14 days if there is no activity.

@windowstoolkitbot
Copy link

This issue seems inactive. It will automatically be closed in 14 days if there is no activity.

@windowstoolkitbot
Copy link

Issue is inactive. It was automatically closed.

@tedrog36
Copy link

tedrog36 commented Jun 6, 2019

It is unfortunate this was closed. This is a pretty serious issue for a very common scenario. It is preventing me from using the DataGrid. Should I resubmit the issue? BTW...I just tested the provided project with the latest stable version of DataGrid (5.1.0) and it still does not work properly.

@tedrog36
Copy link

tedrog36 commented Jun 6, 2019

For anybody else who is wrestling with this issue it can be solved by setting IsReadOnly to true for the DataGridTemplateColumn that contains the CalendarDatePicker. That way you don't have a conflict between the editing mode and the CalendardDatePicker going into its own editing mode.

See code I modified from provided project: I also switched to using x:Bind.

<Page xmlns:my="using:Microsoft.Toolkit.Uwp.UI.Controls" 
    x:Class="DataGridCalendarPickerTemplateBug.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:DataGridCalendarPickerTemplateBug"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

   <Page.Resources>
      <local:StringFormatConverter x:Key="StringFormatConverter"/>
        <DataTemplate x:Key="CalendarCell" x:DataType="local:Item">
            <CalendarDatePicker Date="{x:Bind DateCreatedOffset}" Margin="3,4,3,3"/>
         </DataTemplate>
    </Page.Resources>

    <Grid>
      <StackPanel>
         <StackPanel Orientation="Horizontal" Margin="0,10,0,0">
            <TextBlock Text="Sample Standard CalendarDatePicker on a page:" Margin="5,3,0,0"/>
            <CalendarDatePicker Name="cdpMyDate"  Margin="8,0,0,0" />
         </StackPanel>
   
      <my:DataGrid Name="dgDates" AutoGenerateColumns="false" Margin="8,8,0,0"  BorderBrush="LightGray" BorderThickness="1" GridLinesVisibility="Horizontal" Width="250" Height="200" HorizontalAlignment="Left">
         <my:DataGrid.Columns>
               <my:DataGridTemplateColumn CellTemplate="{StaticResource CalendarCell}" IsReadOnly="True" Header="Date"/>
               <my:DataGridTextColumn Binding="{Binding Text}" Header="Description"/>
            </my:DataGrid.Columns>
      </my:DataGrid>
      </StackPanel>
   </Grid>
</Page>

@ghost ghost locked as resolved and limited conversation to collaborators Nov 26, 2019
@CommunityToolkit CommunityToolkit unlocked this conversation Nov 9, 2020
@Kyaa-dost
Copy link
Contributor

@jcbeppler ⬆️

@Kyaa-dost Kyaa-dost reopened this Nov 9, 2020
@Kyaa-dost
Copy link
Contributor

Seems like this issue is still active as @jcbeppler pointed out in #3557

CC: @anawishnoff @RBrid

@ccarlo88
Copy link

ccarlo88 commented Nov 9, 2020

@Kyaa-dost after I mentioned this issue, I just realized a second issue which is related to WinUI and the CalendarDatePicker. It is possible that the issue there, generates this issue with the toolkit. See here:

microsoft/microsoft-ui-xaml#3571

@Kyaa-dost
Copy link
Contributor

@jcbeppler good catch! There is a possibility. We can find this out once the devs investigate this further. Meanwhile, feel free to dive into further analysis or possible resolution.

@ccarlo88
Copy link

@Kyaa-dost I made a couple of attempts and found out that the same issue exist with the TimePicker using the DataGridTemplateColumn. It is really quite annoying because I don't have a workable way to unselect the current row so the user wouldn't notice the issue.

@Kyaa-dost
Copy link
Contributor

@anawishnoff @RBrid can we please look into this whenever get a chance ⬆️

@ghost
Copy link

ghost commented Jul 8, 2021

Thanks maxmin88 for patiently waiting while the team is still investigating the issue.

@anawishnoff @RBrid can we please have an update on this issue? Thanks

@ghost ghost added the In-PR 🚀 label Jul 30, 2021
@michael-hawker michael-hawker added this to the 7.1 milestone Jul 30, 2021
@CommunityToolkit CommunityToolkit deleted a comment Jul 31, 2021
@CommunityToolkit CommunityToolkit deleted a comment Jul 31, 2021
@CommunityToolkit CommunityToolkit deleted a comment Jul 31, 2021
@ghost ghost removed the In-PR 🚀 label Aug 31, 2021
@ghost ghost added the In-PR 🚀 label Aug 31, 2021
@ghost ghost closed this as completed in #4206 Sep 3, 2021
@ghost ghost removed the In-PR 🚀 label Sep 3, 2021
ghost pushed a commit that referenced this issue Sep 3, 2021
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 -->

<!-- 👉 It is imperative to resolve ONE ISSUE PER PR and avoid making multiple changes unless the changes interrelate with each other --> 

<!-- 📝 Please always keep the "☑️ Allow edits by maintainers" button checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 -->

### Note: This is a copy of the previously reviewed work with a new branch name
## Fixes #2493
<!-- Add the relevant issue number after the "#" mentioned above (for ex: "## Fixes #1234") which will automatically close the issue once the PR is merged. -->

<!-- Add a brief overview here of the feature/bug & fix. -->
This prevents DataGrid from assuming focus should be reset back to itself when a control inside DataGridTemplateColumn gains focus. This is my first WCT PR, so please go easy on me 😆 
## PR Type
What kind of change does this PR introduce?
<!-- Please uncomment one or more options below that apply to this PR. -->
Bugfix 
<!-- - -->
<!-- - Feature -->
<!-- - Code style update (formatting) -->
<!-- - Refactoring (no functional changes, no api changes) -->
<!-- - Build or CI related changes -->
<!-- - Documentation content changes -->
<!-- - Sample app changes -->
<!-- - Other... Please describe: -->


## What is the current behavior?
<!-- Please describe the current behavior that you are modifying, or link to a relevant issue. -->
Trying to open a control like CalendarDatePicker from within a DataGridTemplateColumn doesn't work, as there is specific behavior to detect when DataGrid loses focus and return it. This doesn't make much sense for controls which require focus to function properly.

## What is the new behavior?
<!-- Describe how was this issue resolved or changed? -->
When the DataGrid loses focus, we now specifically detect if the editing column is a DataGridTemplateColumn and alter the behavior to accommodate this.

## PR Checklist

Please check if your PR fulfills the following requirements:

- [x] Tested code with current [supported SDKs](../readme.md#supported)
- [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->
- [ ] Sample in sample app has been added / updated (for bug fixes / features)
    - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/CommunityToolkit/WindowsCommunityToolkit-design-assets)
- [ ] New major technical changes in the toolkit have or will be added to the [Wiki](https://github.com/CommunityToolkit/WindowsCommunityToolkit/wiki) e.g. build changes, source generators, testing infrastructure, sample creation changes, etc...
- [ ] Tests for the changes have been added (for bug fixes / features) (if applicable)
- [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*)
- [x] Contains **NO** breaking changes

<!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below.
     Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. -->


## Other information
I'm unsure if this is the *best* way to do this, but it makes the most sense given how DataGrid already has the capability to detect the editing element and column type.
Additional context before branch rename: #4206
Related: unoplatform/uno#6543
@ghost ghost added the Completed 🔥 label Sep 3, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Nov 3, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug 🐛 An unexpected issue that highlights incorrect behavior Completed 🔥 DataGrid 🔠 Issues on DataGrid control
Projects
None yet