{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/Win2D/issues/427","repository_url":"https://api.github.com/repos/Microsoft/Win2D","labels_url":"https://api.github.com/repos/Microsoft/Win2D/issues/427/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/Win2D/issues/427/comments","events_url":"https://api.github.com/repos/Microsoft/Win2D/issues/427/events","html_url":"https://github.com/Microsoft/Win2D/issues/427","id":177119625,"number":427,"title":"CanvasVirtualControl won't invalidate regions if situated inside RelativePanel","user":{"login":"octav84","id":3714293,"avatar_url":"https://avatars.githubusercontent.com/u/3714293?v=3","gravatar_id":"","url":"https://api.github.com/users/octav84","html_url":"https://github.com/octav84","followers_url":"https://api.github.com/users/octav84/followers","following_url":"https://api.github.com/users/octav84/following{/other_user}","gists_url":"https://api.github.com/users/octav84/gists{/gist_id}","starred_url":"https://api.github.com/users/octav84/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/octav84/subscriptions","organizations_url":"https://api.github.com/users/octav84/orgs","repos_url":"https://api.github.com/users/octav84/repos","events_url":"https://api.github.com/users/octav84/events{/privacy}","received_events_url":"https://api.github.com/users/octav84/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2016-09-15T08:36:34Z","updated_at":"2016-09-15T08:36:34Z","closed_at":null,"body":"Hi,\r\nI have a CanvasVirtualControl inside a RelativePanel XAML (UWP) control. Well, the exact structure is more complicated, but the only thing I noticed is the RelativePanel has something to do with it. The CanvasVirtualControl won't invalidate regions. Previously, there was a Grid instead of the RelativePanel and everithing worked fine. I happen to need the RelativePanel because it fixes another bug.\r\n\r\nThis is the XAML of the page:\r\n\r\n     <Page x:Class=\"Cerner.Pulse.UI.Views.ReviewViews.LabResultsPage\"\r\n      xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"\r\n      xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"\r\n      xmlns:canvas=\"using:Microsoft.Graphics.Canvas.UI.Xaml\"\r\n      xmlns:converters=\"using:Cerner.Pulse.UI.Converters\"\r\n      xmlns:core=\"using:Microsoft.Xaml.Interactions.Core\"\r\n      xmlns:d=\"http://schemas.microsoft.com/expression/blend/2008\"\r\n      xmlns:data=\"using:Cerner.Pulse.UI.Util.ReviewUtil\"\r\n      xmlns:interactivity=\"using:Microsoft.Xaml.Interactivity\"\r\n      xmlns:mc=\"http://schemas.openxmlformats.org/markup-compatibility/2006\"\r\n      xmlns:uc=\"using:Cerner.Pulse.UI.UserControls\"\r\n      xmlns:utils=\"using:Cerner.Pulse.UI.Util\"\r\n      DataContext=\"{Binding LabResultsViewModel,\r\n                            Source={StaticResource locator}}\"\r\n      Loaded=\"Page_Loaded\"\r\n      mc:Ignorable=\"d\">\r\n    <Page.Resources>\r\n        <converters:BooleanToVisibilityConverter x:Key=\"BooleanToVisibilityConverter\" />\r\n        <converters:BooleanToInvisibilityConverter x:Key=\"BooleanToInvisibilityConverter\" />\r\n    </Page.Resources>\r\n    <!--<Grid x:Name=\"MainGrid\">\r\n        <Grid.RowDefinitions>\r\n            <RowDefinition Height=\"Auto\" />\r\n            <RowDefinition Height=\"Auto\" />\r\n            <RowDefinition Height=\"*\" />\r\n        </Grid.RowDefinitions>-->\r\n\r\n    <RelativePanel HorizontalAlignment=\"Stretch\" VerticalAlignment=\"Stretch\">\r\n        <Popup x:Name=\"LabResultsPopup\"\r\n               HorizontalOffset=\"{Binding LabResultPopupPosition.X}\"\r\n               IsLightDismissEnabled=\"True\"\r\n               VerticalOffset=\"{Binding LabResultPopupPosition.Y}\">\r\n            <uc:LabResultsDetailsPopup x:Name=\"LabResultsDetailsUserControl\" />\r\n        </Popup>\r\n\r\n        <uc:PageHeader x:Name=\"LabResultsPageHeader\"\r\n                       HasLeftSideButtonSet=\"True\"\r\n                       HasLeftSideGlyphButton=\"True\"\r\n                       HasLeftSideTextButton=\"True\"\r\n                       HasRightSideButtonSet=\"False\"\r\n                       LeftSideButtonCommand=\"{Binding NavigateBackCommand}\"\r\n                       LeftSideButtonGlyphCode=\"&#xE973;\"\r\n                       LeftSideButtonText=\"{Binding LeftSideButtonText}\"\r\n                       PageTitle=\"{Binding PageTitle}\"\r\n                       RelativePanel.AlignLeftWithPanel=\"True\"\r\n                       RelativePanel.AlignRightWithPanel=\"True\"\r\n                       RelativePanel.AlignTopWithPanel=\"True\" />\r\n\r\n        <!--  Filters  -->\r\n\r\n        <Border Name=\"FiltersBorder\"\r\n                Height=\"{StaticResource DefaultPageTitleHeight}\"\r\n                Background=\"{StaticResource LabResultsCategoriesOddRowBackground}\"\r\n                BorderBrush=\"{StaticResource DividerLineBrush}\"\r\n                BorderThickness=\"0,0,0,1\"\r\n                RelativePanel.AlignLeftWithPanel=\"True\"\r\n                RelativePanel.AlignRightWithPanel=\"True\"\r\n                RelativePanel.Below=\"LabResultsPageHeader\">\r\n            <RelativePanel Margin=\"15,0,15,0\"\r\n                           HorizontalAlignment=\"Stretch\"\r\n                           VerticalAlignment=\"Stretch\">\r\n                <!--\r\n                    a weird bug appears if opening popup from viewmodel: open Lab Results, go back, open Lab Results\r\n                    again and now open a filters popup: BANG - 2 popups show instead of 1\r\n                    Open popup from page instead and it's ok\r\n                -->\r\n                <RelativePanel Width=\"430\" RelativePanel.AlignHorizontalCenterWithPanel=\"True\">\r\n                    <Button Name=\"SectionsFilterButton\"\r\n                            Margin=\"100,0,0,0\"\r\n                            RelativePanel.AlignLeftWithPanel=\"true\"\r\n                            Style=\"{StaticResource DefaultTextButton}\"\r\n                            Tapped=\"SectionsFilterButton_Tapped\">\r\n                        <!--<interactivity:Interaction.Behaviors>\r\n                        <core:EventTriggerBehavior EventName=\"Tapped\">\r\n                            <core:InvokeCommandAction Command=\"{Binding ShowSectionsFilterCommand, Mode=OneWay}\" />\r\n                        </core:EventTriggerBehavior>\r\n                    </interactivity:Interaction.Behaviors>-->\r\n                        <StackPanel Orientation=\"Horizontal\">\r\n                            <TextBlock FontSize=\"{StaticResource SmallTextSize}\"\r\n                                       Style=\"{StaticResource DefaultButtonTextBlockStyle}\"\r\n                                       Text=\"{Binding SectionsFilterButtonText}\" />\r\n                            <TextBlock Margin=\"3,6,0,0\"\r\n                                       FontWeight=\"Bold\"\r\n                                       Style=\"{StaticResource SmallButtonGlyphBlockStyle}\"\r\n                                       Text=\"&#xE936;\" />\r\n                        </StackPanel>\r\n                    </Button>\r\n\r\n                    <Popup x:Name=\"SectionsFilterPopup\"\r\n                           Width=\"300\"\r\n                           Closed=\"Popup_Closed\"\r\n                           IsLightDismissEnabled=\"True\"\r\n                           IsOpen=\"{Binding IsOpenSectionsFilterPopup,\r\n                                            Mode=TwoWay}\"\r\n                           Opened=\"Popup_OnOpened\"\r\n                           RelativePanel.AlignLeftWithPanel=\"True\"\r\n                           RelativePanel.Below=\"SectionsFilterButton\">\r\n                        <uc:LabResultsSectionsFilterPopup x:Name=\"LabResultsSectionsFilter\" />\r\n                    </Popup>\r\n\r\n                    <Button Name=\"NormalcyFilterButton\"\r\n                            Margin=\"0,0,100,0\"\r\n                            RelativePanel.AlignRightWithPanel=\"True\"\r\n                            Style=\"{StaticResource DefaultTextButton}\"\r\n                            Tapped=\"NormalcyFilterButton_Tapped\">\r\n                        <!--<interactivity:Interaction.Behaviors>\r\n                        <core:EventTriggerBehavior EventName=\"Tapped\">\r\n                            <core:InvokeCommandAction Command=\"{Binding ShowNormalcyFilterCommand, Mode=OneWay}\"\r\n                                                      CommandParameter=\"{Binding RelativeSource={RelativeSource Self }, Path=Parent}\" />\r\n                        </core:EventTriggerBehavior>\r\n                    </interactivity:Interaction.Behaviors>-->\r\n                        <StackPanel Orientation=\"Horizontal\">\r\n                            <TextBlock FontSize=\"{StaticResource SmallTextSize}\"\r\n                                       Style=\"{StaticResource DefaultButtonTextBlockStyle}\"\r\n                                       Text=\"{Binding NormalcyFilterButtonText}\" />\r\n                            <TextBlock Margin=\"3,6,0,0\"\r\n                                       FontWeight=\"Bold\"\r\n                                       Style=\"{StaticResource SmallButtonGlyphBlockStyle}\"\r\n                                       Text=\"&#xE936;\" />\r\n                        </StackPanel>\r\n                    </Button>\r\n\r\n                    <Popup x:Name=\"NormalcyFilterPopup\"\r\n                           Width=\"300\"\r\n                           Closed=\"Popup_Closed\"\r\n                           IsLightDismissEnabled=\"True\"\r\n                           IsOpen=\"{Binding IsOpenNormalcyFilterPopup,\r\n                                            Mode=TwoWay}\"\r\n                           Opened=\"Popup_OnOpened\"\r\n                           RelativePanel.AlignRightWithPanel=\"True\"\r\n                           RelativePanel.Below=\"NormalcyFilterButton\">\r\n                        <uc:LabResultsNormalcyFilterPopup x:Name=\"LabResultsNormalcyFilterPopup\" />\r\n                    </Popup>\r\n\r\n                </RelativePanel>\r\n\r\n                <Button Name=\"ResetFiltersButton\"\r\n                        IsEnabled=\"{Binding IsResetFilterButtonEnabled}\"\r\n                        RelativePanel.AlignHorizontalCenterWithPanel=\"true\"\r\n                        RelativePanel.AlignRightWithPanel=\"True\"\r\n                        Style=\"{StaticResource DefaultTextButton}\">\r\n                    <interactivity:Interaction.Behaviors>\r\n                        <core:EventTriggerBehavior EventName=\"Tapped\">\r\n                            <core:InvokeCommandAction Command=\"{Binding ResetButtonCommand, Mode=OneWay}\" />\r\n                        </core:EventTriggerBehavior>\r\n                    </interactivity:Interaction.Behaviors>\r\n                    <TextBlock x:Uid=\"reset\"\r\n                               FontSize=\"{StaticResource SmallTextSize}\"\r\n                               Style=\"{StaticResource DefaultButtonTextBlockStyle}\" />\r\n                </Button>\r\n            </RelativePanel>\r\n        </Border>\r\n\r\n        <!--USING THIS GRID MAKES THE CANVAS VIRTUAL CONTROL WORK-->\r\n        <!--<Grid RelativePanel.Below=\"FiltersBorder\" Visibility=\"{Binding IsLoading, Converter={StaticResource BooleanToInvisibilityConverter}}\">\r\n            <Grid.ColumnDefinitions>\r\n                <ColumnDefinition Width=\"Auto\" />\r\n                <ColumnDefinition Width=\"*\" />\r\n            </Grid.ColumnDefinitions>-->\r\n\r\n        <!--USING THIS RELATIVE PANEL MAKES THE ON_REGIONS_INVALIDATED NOT FIRE-->\r\n        <RelativePanel RelativePanel.Below=\"FiltersBorder\" Visibility=\"{Binding IsLoading, Converter={StaticResource BooleanToInvisibilityConverter}}\">\r\n\r\n            <!--  Categories & \"Most recent result\" column  -->\r\n            <ListView x:Name=\"CategoriesPanel\"\r\n                      Margin=\"0, 0, 0, 0\"\r\n                      Background=\"Transparent\"\r\n                      IsItemClickEnabled=\"True\"\r\n                      ItemContainerStyle=\"{StaticResource LabResultsCategoriesListViewItemStyle}\"\r\n                      ItemTemplate=\"{StaticResource CategoriesItemTemplate}\"\r\n                      ItemsSource=\"{x:Bind Path=LabResultsViewModel.LabResultsDetailsCollection.View, Mode=OneWay}\"\r\n                      RelativePanel.AlignLeftWithPanel=\"True\"\r\n                      ScrollViewer.VerticalScrollBarVisibility=\"Hidden\">\r\n                <ListView.GroupStyle>\r\n                    <GroupStyle HeaderContainerStyle=\"{StaticResource LabResultsCategoriesHeaderStyle}\" HeaderTemplate=\"{StaticResource CategoriesHeaderTemplate}\" />\r\n                </ListView.GroupStyle>\r\n                <interactivity:Interaction.Behaviors>\r\n                    <core:EventTriggerBehavior EventName=\"Loaded\">\r\n                        <core:InvokeCommandAction Command=\"{Binding BindListViewCommand, Mode=OneWay}\" CommandParameter=\"{Binding ElementName=CategoriesPanel}\" />\r\n                    </core:EventTriggerBehavior>\r\n                    <core:EventTriggerBehavior EventName=\"ItemClick\">\r\n                        <core:InvokeCommandAction Command=\"{Binding CategoriesPanelItemClick}\" />\r\n                    </core:EventTriggerBehavior>\r\n                </interactivity:Interaction.Behaviors>\r\n            </ListView>\r\n\r\n            <!--  Values table  -->\r\n            <ScrollViewer HorizontalScrollBarVisibility=\"Auto\"\r\n                          ManipulationMode=\"All\"\r\n                          RelativePanel.AlignRightWithPanel=\"True\"\r\n                          RelativePanel.RightOf=\"CategoriesPanel\"\r\n                          Style=\"{StaticResource CanvasScrollViewerStyle}\"\r\n                          VerticalScrollBarVisibility=\"Disabled\">\r\n                <!--<Grid>\r\n                    <Grid.RowDefinitions>\r\n                        <RowDefinition Height=\"Auto\" />\r\n                        <RowDefinition Height=\"*\" />\r\n                    </Grid.RowDefinitions>-->\r\n\r\n                <RelativePanel>\r\n                    <ListView x:Name=\"ValuesHeaderListView\"\r\n                              Margin=\"0\"\r\n                              ItemContainerStyle=\"{StaticResource LabResultsValuesListHeaderItemTemplate}\"\r\n                              ItemTemplate=\"{StaticResource ValuesHeaderTemplate}\"\r\n                              ItemsSource=\"{Binding HospitalizationDates}\"\r\n                              Padding=\"0\"\r\n                              RelativePanel.AlignLeftWithPanel=\"True\"\r\n                              RelativePanel.AlignRightWithPanel=\"True\">\r\n                        <ListView.ItemsPanel>\r\n                            <ItemsPanelTemplate>\r\n                                <ItemsStackPanel Margin=\"0\" Orientation=\"Horizontal\" />\r\n                            </ItemsPanelTemplate>\r\n                        </ListView.ItemsPanel>\r\n                    </ListView>\r\n\r\n                    <ScrollViewer x:Name=\"CanvasScroll\"\r\n                                  HorizontalScrollBarVisibility=\"Disabled\"\r\n                                  RelativePanel.AlignLeftWithPanel=\"True\"\r\n                                  RelativePanel.AlignRightWithPanel=\"True\"\r\n                                  VerticalScrollBarVisibility=\"Auto\"\r\n                                  VerticalScrollMode=\"Enabled\"\r\n                                  ZoomMode=\"Disabled\">\r\n                        <!--  Tapped=\"LabResultsCanvas_OnTapped\"  -->\r\n                        <canvas:CanvasVirtualControl x:Name=\"LabResultsCanvas\"\r\n                                                     ClearColor=\"White\"\r\n                                                     CreateResources=\"LabResultsCanvas_CreateResources\"\r\n                                                     DataContext=\"{Binding CanvasMatrixChanged,\r\n                                                                           Mode=OneWay}\"\r\n                                                     DataContextChanged=\"LabResultsCanvas_DataContextChanged\"\r\n                                                     Loaded=\"LabResultsCanvas_OnLoaded\"\r\n                                                     RegionsInvalidated=\"OnRegionsInvalidated\"\r\n                                                     Unloaded=\"LabResultsCanvas_OnUnloaded\" />\r\n                    </ScrollViewer>\r\n                    <!--</Grid>-->\r\n                </RelativePanel>\r\n            </ScrollViewer>\r\n        </RelativePanel>\r\n        <!--</Grid>-->\r\n\r\n        <ProgressBar Grid.Row=\"2\"\r\n                     Margin=\"7\"\r\n                     VerticalAlignment=\"Center\"\r\n                     Foreground=\"{StaticResource DividerLineBrushDark}\"\r\n                     IsIndeterminate=\"True\"\r\n                     Visibility=\"{Binding IsLoading,\r\n                                          Converter={StaticResource BooleanToVisibilityConverter}}\" />\r\n        <!--</Grid>-->\r\n    </RelativePanel>\r\n</Page>\r\n\r\nThis is the code behind:\r\n\r\nusing Cerner.Pulse.Common.Enums;\r\nusing Cerner.Pulse.UI.Util;\r\nusing Cerner.Pulse.UI.Util.ReviewUtil;\r\nusing Cerner.Pulse.UI.ViewModels.LabResults;\r\nusing GalaSoft.MvvmLight.Ioc;\r\nusing Microsoft.Graphics.Canvas;\r\nusing Microsoft.Graphics.Canvas.Brushes;\r\nusing Microsoft.Graphics.Canvas.UI;\r\nusing Microsoft.Graphics.Canvas.UI.Xaml;\r\nusing System;\r\nusing System.Collections.Generic;\r\nusing System.Linq;\r\nusing System.Threading.Tasks;\r\nusing Windows.Foundation;\r\nusing Windows.UI;\r\nusing Windows.UI.Xaml;\r\nusing Windows.UI.Xaml.Controls;\r\nusing Windows.UI.Xaml.Controls.Primitives;\r\nusing Windows.UI.Xaml.Input;\r\nusing Windows.UI.Xaml.Media;\r\nusing Windows.UI.Xaml.Navigation;\r\n\r\n// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238\r\n\r\nnamespace Cerner.Pulse.UI.Views.ReviewViews\r\n{\r\n\t/// <summary>\r\n\t/// An empty page that can be used on its own or navigated to within a Frame.\r\n\t/// </summary>\r\n\tpublic sealed partial class LabResultsPage : Page\r\n\t{\r\n\t\tpublic LabResultsViewModel LabResultsViewModel { get; set; }\r\n\r\n\t\tprivate static bool isDirty;\r\n\t\tprivate bool isCanvasLoaded = false;\t\t\r\n\r\n\t\tScrollViewer categoriesListScroll;\r\n\t\tprivate LabResultRectangleGraphicProcessor labResultsGraphicProcessor;\r\n\t\tprivate Dictionary<int, CanvasBitmap> IconsDictionary { get; set; }\r\n\t\t//private double exactItemWidthToComplyWithHeader = 150;\r\n\t\tprivate List<Point> tableHeaderItemsCoordinates;\r\n\r\n\t\tprivate const double OPACITY_FACTOR = 0.3;\r\n\t\tprivate const double NO_OPACITY = 1;\r\n\r\n\t\tpublic LabResultsPage()\r\n\t\t{\r\n\t\t\tInitializeComponent();\r\n\r\n\t\t\tLabResultsViewModel = SimpleIoc.Default.GetInstance<LabResultsViewModel>();\r\n\t\t\tlabResultsGraphicProcessor = new LabResultRectangleGraphicProcessor();\r\n\t\t\tIconsDictionary = new Dictionary<int, CanvasBitmap>();\r\n\t\t}\r\n\r\n\t\tprotected override void OnNavigatedTo(NavigationEventArgs e)\r\n\t\t{\r\n\t\t\tbase.OnNavigatedTo(e);\r\n\r\n            //keep filters if navigated back from Details view or from Phone Filters pages\r\n            if (e.NavigationMode == NavigationMode.Back)\r\n                return;\r\n\r\n            LabResultsViewModel.SelectedResultCategoryName = e.Parameter.ToString();                        \r\n            LabResultsViewModel.Filters = new Common.Models.LabResultsFilter { FlagFilter = null, GroupIds = null }; // to reset filtering\r\n\t\t}\r\n\r\n\t\tprivate ScrollViewer GetScrollViewer(DependencyObject depObj)\r\n\t\t{\r\n\t\t\tif (depObj is ScrollViewer) return depObj as ScrollViewer;\r\n\r\n\t\t\tfor (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)\r\n\t\t\t{\r\n\t\t\t\tvar child = VisualTreeHelper.GetChild(depObj, i);\r\n\r\n\t\t\t\tvar result = GetScrollViewer(child);\r\n\t\t\t\tif (result != null) return result;\r\n\t\t\t}\r\n\t\t\treturn null;\r\n\t\t}\r\n\r\n\t\tprivate void Page_Loaded(object sender, RoutedEventArgs e)\r\n\t\t{\r\n\t\t\tcategoriesListScroll = GetScrollViewer(CategoriesPanel);\r\n\r\n\t\t\tcategoriesListScroll.RegisterPropertyChangedCallback(ScrollViewer.VerticalOffsetProperty, (s, dp) =>\r\n\t\t\t{\r\n\t\t\t\tCanvasScroll.ChangeView(CanvasScroll.HorizontalOffset,\r\n\t\t\t\t\tcategoriesListScroll.VerticalOffset, CanvasScroll.ZoomFactor, true);\r\n\t\t\t});\r\n\r\n\t\t\tCanvasScroll.RegisterPropertyChangedCallback(ScrollViewer.VerticalOffsetProperty, (s, dp) =>\r\n\t\t\t{\r\n\t\t\t\tcategoriesListScroll.ChangeView(categoriesListScroll.HorizontalOffset,\r\n\t\t\t\t\tCanvasScroll.VerticalOffset, categoriesListScroll.ZoomFactor, true);\r\n\t\t\t});\r\n\r\n\t\t\tLabResultsCanvas?.Invalidate();\r\n\t\t}\r\n\r\n\t\tprivate void Popup_Closed(object sender, object e)\r\n\t\t{\r\n\t\t\tBackground = new SolidColorBrush(Colors.Transparent);\r\n\t\t\tOpacity = NO_OPACITY;\r\n\t\t\tLabResultsViewModel.IsOpenLabResultPopup = false;\r\n\t\t\tLabResultsViewModel.IsOpenNormalcyFilterPopup = false;\r\n\t\t}\r\n\r\n\t\tprivate void SectionsPopup_Closed(object sender, object e)\r\n\t\t{\r\n\t\t\tBackground = new SolidColorBrush(Colors.Transparent);\r\n\t\t\tLabResultsViewModel.IsOpenSectionsFilterPopup = false;\r\n\t\t\tOpacity = NO_OPACITY;\r\n\t\t}\r\n\r\n\t\tprivate void NormalciesPopup_Closed(object sender, object e)\r\n\t\t{\r\n\t\t\tBackground = new SolidColorBrush(Colors.Transparent);\r\n\t\t\tLabResultsViewModel.IsOpenNormalcyFilterPopup = false;\r\n\t\t\tOpacity = NO_OPACITY;\r\n\t\t}\r\n\r\n\t\tprivate void LabResultsCanvas_CreateResources(CanvasVirtualControl sender, CanvasCreateResourcesEventArgs args)\r\n\t\t{\r\n\t\t\targs.TrackAsyncAction(CreateResourcesAsync(sender).AsAsyncAction());\r\n\t\t}\r\n\r\n\t\tasync Task CreateResourcesAsync(ICanvasResourceCreator sender)\r\n\t\t{\r\n\t\t\tawait LabResultsViewModel.LoadLabResults();\r\n\r\n\t\t\tvar bitmap = await CanvasBitmap.LoadAsync(sender, new Uri(\"ms-appx:///Assets/high.png\", UriKind.Absolute));\r\n\t\t\tIconsDictionary.Add((int)AbnormalFlagType.AboveHighNormal, bitmap);\r\n\t\t\tbitmap = await CanvasBitmap.LoadAsync(sender, new Uri(\"ms-appx:///Assets/low.png\", UriKind.Absolute));\r\n\t\t\tIconsDictionary.Add((int)AbnormalFlagType.BelowLowNormal, bitmap);\r\n\t\t\tbitmap = await CanvasBitmap.LoadAsync(sender, new Uri(\"ms-appx:///Assets/criticalHigh.png\", UriKind.Absolute));\r\n\t\t\tIconsDictionary.Add((int)AbnormalFlagType.CriticalHigh, bitmap);\r\n\t\t\tbitmap = await CanvasBitmap.LoadAsync(sender, new Uri(\"ms-appx:///Assets/criticalLow.png\", UriKind.Absolute));\r\n\t\t\tIconsDictionary.Add((int)AbnormalFlagType.CriticalLow, bitmap);\r\n\t\t}\r\n\r\n\t\tprivate void CalculateCanvasDimmensions()\r\n\t\t{\r\n\t\t\t//to ensure compliance with the header - XAML does some smart calculations and comes up with unexpected resultst   \r\n\t\t\t//LabResultsCanvas.Width = ValuesHeaderListView.ActualWidth;\r\n\r\n\t\t\tLabResultsCanvas.Width = LabResultsViewModel.HospitalizationDates.Count * LabResultsConstants.LabResultCellWidth;\r\n\t\t\tif (LabResultsViewModel.CanvasMatrix != null)\r\n\t\t\t\tLabResultsCanvas.Height = LabResultsViewModel.CanvasMatrix.GetLength(0) * LabResultsConstants.LabResultCellHeight;\r\n\t\t}\r\n\r\n\t\tprivate void OnRegionsInvalidated(CanvasVirtualControl sender, CanvasRegionsInvalidatedEventArgs args)\r\n\t\t{\r\n\t\t\tif (!isDirty)\r\n\t\t\t{\r\n\t\t\t\tCalculateCanvasDimmensions();\r\n\r\n\t\t\t\ttableHeaderItemsCoordinates = GetExactHeaderItemsCoordinates().ToList();\r\n\t\t\t\t\r\n\t\t\t\tisDirty = true;\r\n\t\t\t}\r\n\r\n\t\t\tforeach (var region in args.InvalidatedRegions)\r\n\t\t\t{\r\n\t\t\t\tDrawRegion(sender, region);\r\n\t\t\t}\r\n\t\t\tLabResultsCanvas.VerticalAlignment = VerticalAlignment.Top;\r\n\t\t\tLabResultsCanvas.HorizontalAlignment = HorizontalAlignment.Left;\r\n\r\n\t\t\tThickness margin = LabResultsCanvas.Margin;\r\n\t\t\tmargin.Top = -1 * LabResultsConstants.LabResultCellHeight;\r\n\t\t\tLabResultsCanvas.Margin = margin;\r\n\r\n\t\t\tCanvasScroll.ChangeView(CanvasScroll.HorizontalOffset,\r\n\t\t\t\t\tcategoriesListScroll.VerticalOffset, CanvasScroll.ZoomFactor, true);\r\n\r\n\t\t}\r\n\r\n\t\tprivate void DrawRegion(CanvasVirtualControl sender, Rect region)\r\n\t\t{\r\n\t\t\tif (LabResultsViewModel.CanvasMatrix == null)\r\n\t\t\t\treturn;\r\n\r\n\t\t\tusing (var ds = sender.CreateDrawingSession(region))\r\n\t\t\t{\r\n\t\t\t\tds.Antialiasing = CanvasAntialiasing.Aliased;\r\n\r\n\t\t\t\tint left, right, top, bottom;\r\n\r\n\t\t\t\tlabResultsGraphicProcessor.CalculateRegionBounds(region, LabResultsConstants.LabResultCellWidth,\r\n\t\t\t\t\tout left, out right, out top, out bottom);\r\n\r\n\t\t\t\tfor (int x = left; x <= right; x++)\r\n\t\t\t\t{\r\n\t\t\t\t\tif (x < 0 || x >= LabResultsViewModel.CanvasMatrix[0].Length) //fail-safe - ensure only valid regions are drawn\r\n\t\t\t\t\t\tcontinue;\r\n\r\n\t\t\t\t\tvar exactXToAlignWithHeader = tableHeaderItemsCoordinates[x].X;\r\n\r\n\t\t\t\t\tfor (int y = top; y <= bottom; y++)\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (!AreCoordinatesInsideCanvas(x * LabResultsConstants.LabResultCellWidth, y * LabResultsConstants.LabResultCellHeight))\r\n\t\t\t\t\t\t\tcontinue;\r\n\r\n                        //skip header row - it's redundant - it would be hidden behind ListView header \r\n                       // and would cause visual issues when scrolling on a touch screen\r\n                        if (y == 0)\r\n                            continue;\r\n\r\n\t\t\t\t\t\tvar labResultCellDrawingModel = LabResultsViewModel.CanvasMatrix[y][x];\r\n\r\n\t\t\t\t\t\tlabResultCellDrawingModel.SetDrawingParameters\r\n\t\t\t\t\t\t\t(\r\n\t\t\t\t\t\t\t\texactXToAlignWithHeader,\r\n\t\t\t\t\t\t\t\ty * LabResultsConstants.LabResultCellHeight,\r\n\t\t\t\t\t\t\t\tLabResultsConstants.LabResultCellWidth,\r\n\t\t\t\t\t\t\t\tds\r\n\t\t\t\t\t\t\t);\r\n\r\n\t\t\t\t\t\tif (labResultCellDrawingModel.HasIcon)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlabResultCellDrawingModel.Icon.Image = IconsDictionary[labResultCellDrawingModel.LabResult.AbnormalFlag];\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tif (labResultCellDrawingModel.Canvas == null)\r\n\t\t\t\t\t\t\tlabResultCellDrawingModel.Canvas = sender;\r\n\r\n\t\t\t\t\t\tif (labResultCellDrawingModel.Border != null && labResultCellDrawingModel.Type == LabResultCellType.Value)\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tlabResultCellDrawingModel.Border.CustomBorderBrush = new BorderBrush\r\n\t\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\t\tRight = GetRightBorderBrush(sender)\r\n\t\t\t\t\t\t\t};\r\n\t\t\t\t\t\t\tlabResultCellDrawingModel.BorderOffset = new BorderOffset { Right = 7 };\r\n\t\t\t\t\t\t}\r\n\r\n\t\t\t\t\t\tlabResultsGraphicProcessor.DrawIconAndTextRectangleCell(labResultCellDrawingModel);\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate bool AreCoordinatesInsideCanvas(double x, double y)\r\n\t\t{\r\n\t\t\tint matrixHeight = LabResultsViewModel.CanvasMatrix.GetLength(0);\r\n\t\t\tint matrixWidth = LabResultsViewModel.CanvasMatrix[0].Length;\r\n\r\n\t\t\treturn\r\n\t\t\t\ty / LabResultsConstants.LabResultCellHeight >= 0 &&\r\n\t\t\t\ty / LabResultsConstants.LabResultCellHeight < matrixHeight &&\r\n\t\t\t\tx / LabResultsConstants.LabResultCellWidth >= 0 &&\r\n\t\t\t\tx / LabResultsConstants.LabResultCellWidth < matrixWidth;\r\n\t\t}\t\t\r\n\r\n\t\tprivate void LabResultsCanvas_OnUnloaded(object sender, RoutedEventArgs e)\r\n\t\t{\r\n\t\t\tisDirty = false;\r\n\t\t\tLabResultsCanvas.RemoveFromVisualTree();\r\n\t\t\tLabResultsCanvas = null;\r\n\t\t\tisCanvasLoaded = false;\r\n\t\t}\r\n\r\n\t\tprivate IEnumerable<Point> GetExactHeaderItemsCoordinates()\r\n\t\t{\r\n\t\t\tdouble offset = 0;\r\n\t\t\tvar pointsToReturn = new List<Point>();\r\n\r\n\t\t\tfor (int i = 0; i < ValuesHeaderListView.Items.Count; i++)\r\n\t\t\t{\r\n\t\t\t\tvar headerItem = ValuesHeaderListView.ContainerFromIndex(i) as ListViewItem;\r\n\r\n\t\t\t\tif (headerItem == null)\r\n\t\t\t\t\tthrow new Exception(\"Unexpected page rendering exception\");\r\n\r\n\t\t\t\tvar ttv = headerItem.TransformToVisual(Window.Current.Content);\r\n\t\t\t\tPoint screenCoords = ttv.TransformPoint(new Point(0, 0));\r\n\r\n\t\t\t\tif (i == 0)\r\n\t\t\t\t\toffset = screenCoords.X;\r\n\r\n\t\t\t\tscreenCoords.X = screenCoords.X - offset;\r\n\t\t\t\tpointsToReturn.Add(screenCoords);\r\n\t\t\t}\r\n\r\n\t\t\treturn pointsToReturn;\r\n\t\t}\r\n\r\n\t\tprivate CanvasLinearGradientBrush GetRightBorderBrush(ICanvasResourceCreator canvas)\r\n\t\t{\r\n\t\t\treturn new CanvasLinearGradientBrush(canvas, new CanvasGradientStop[]\r\n\t\t\t{\r\n\t\t\t\t\tnew CanvasGradientStop\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tColor = Colors.White,\r\n\t\t\t\t\t\tPosition = 0\r\n\t\t\t\t\t},\r\n\t\t\t\t\tnew CanvasGradientStop\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tColor = LabResultsConstants.BorderColor,\r\n\t\t\t\t\t\tPosition = 0.333f\r\n\t\t\t\t\t},\r\n\t\t\t\t\tnew CanvasGradientStop\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tColor = LabResultsConstants.BorderColor,\r\n\t\t\t\t\t\tPosition = 0.667f\r\n\t\t\t\t\t},\r\n\t\t\t\t\tnew CanvasGradientStop\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tColor = Colors.White,\r\n\t\t\t\t\t\tPosition = 1\r\n\t\t\t\t\t}\r\n\t\t\t});\r\n\t\t}\r\n\r\n\t\tprivate void LabResultsCanvas_DataContextChanged(FrameworkElement sender, DataContextChangedEventArgs args)\r\n\t\t{\r\n\t\t\tif (LabResultsViewModel?.CanvasMatrix != null && LabResultsViewModel.CanvasMatrix.Any() && LabResultsCanvas != null && isCanvasLoaded)\r\n\t\t\t{\r\n\t\t\t\tisDirty = false;\r\n\t\t\t\tLabResultsCanvas.Invalidate();\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\tprivate void Popup_OnOpened(object sender, object e)\r\n\t\t{\r\n\t\t\tOpacity = OPACITY_FACTOR;\r\n\t\t}\r\n\r\n\t\tprivate void LabResultsCanvas_OnLoaded(object sender, RoutedEventArgs e)\r\n\t\t{\r\n\t\t\tisCanvasLoaded = true;\r\n\t\t}\r\n\r\n\t\tprivate void NormalcyFilterButton_Tapped(object sender, TappedRoutedEventArgs e)\r\n\t\t{\r\n\t\t\tNormalcyFilterPopup.IsOpen = true;\r\n\t\t}\r\n\r\n\t\tprivate void SectionsFilterButton_Tapped(object sender, TappedRoutedEventArgs e)\r\n\t\t{\r\n\t\t\tSectionsFilterPopup.IsOpen = true;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n\r\nThank you"}}
{"actor":{"display_login":"octav84"}}