Skip to content

Commit

Permalink
Fix a TreeViewItemAutomationPeer crash (#1449)
Browse files Browse the repository at this point in the history
* Fix TreeViewItemAutomationPeer

* CR feedback
  • Loading branch information
kaiguo authored and msft-github-bot committed Oct 16, 2019
1 parent ab66b66 commit 102ae5c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions dev/TreeView/TreeViewItemAutomationPeer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,17 @@ int32_t TreeViewItemAutomationPeer::GetPositionInSetCore()
{
winrt::ListView ancestorListView = GetParentListView();
auto targetNode = GetTreeViewNode();
int positionInSet = -1;
int positionInSet = 0;

if (ancestorListView && targetNode)
{
auto targetParentNode = targetNode.Parent();
UINT32 position = 0;
if (targetParentNode.Children().IndexOf(targetNode, position))
if (const auto targetParentNode = targetNode.Parent())
{
positionInSet = static_cast<int>(position) + 1;
UINT32 position = 0;
if (targetParentNode.Children().IndexOf(targetNode, position))
{
positionInSet = static_cast<int>(position) + 1;
}
}
}

Expand All @@ -133,13 +135,15 @@ int32_t TreeViewItemAutomationPeer::GetSizeOfSetCore()
{
winrt::ListView ancestorListView = GetParentListView();
auto targetNode = GetTreeViewNode();
int setSize = -1;
int setSize = 0;

if (ancestorListView && targetNode)
{
auto targetParentNode = targetNode.Parent();
UINT32 size = targetParentNode.Children().Size();
setSize = static_cast<int>(size);
if (const auto targetParentNode = targetNode.Parent())
{
UINT32 size = targetParentNode.Children().Size();
setSize = static_cast<int>(size);
}
}

return setSize;
Expand Down

0 comments on commit 102ae5c

Please sign in to comment.