mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
replace static_cast by dynamic_cast
This commit is contained in:
parent
7295fad2b1
commit
9c6e929edc
3 changed files with 11 additions and 11 deletions
|
@ -57,8 +57,7 @@
|
|||
|
||||
<DataTemplate x:Key="HistoryItemTemplate" x:DataType="model:HistoryItemViewModel">
|
||||
<muxc:SwipeControl RightItems="{StaticResource HistorySwipeItems}">
|
||||
<StackPanel Margin="0,6,4,6"
|
||||
Background="Transparent">
|
||||
<StackPanel Margin="0,6,4,6" Background="Transparent">
|
||||
<TextBlock x:Name="ExprTextBlock"
|
||||
Margin="0,0,0,4"
|
||||
HorizontalAlignment="Right"
|
||||
|
|
|
@ -42,11 +42,11 @@ HistoryList::HistoryList()
|
|||
|
||||
void HistoryList::ListView_ItemClick(_In_ Object^ sender, _In_ ItemClickEventArgs^ e)
|
||||
{
|
||||
HistoryViewModel^ historyVM = static_cast<HistoryViewModel^>(this->DataContext);
|
||||
HistoryItemViewModel^ clickedItem = safe_cast<HistoryItemViewModel^>(e->ClickedItem);
|
||||
HistoryViewModel^ historyVM = dynamic_cast<HistoryViewModel^>(this->DataContext);
|
||||
HistoryItemViewModel^ clickedItem = dynamic_cast<HistoryItemViewModel^>(e->ClickedItem);
|
||||
|
||||
// When the user clears the history list in the overlay view and presses enter, the clickedItem is nullptr
|
||||
if (clickedItem != nullptr)
|
||||
if (clickedItem != nullptr && historyVM != nullptr)
|
||||
{
|
||||
historyVM->ShowItem(clickedItem);
|
||||
}
|
||||
|
@ -55,8 +55,7 @@ void HistoryList::ListView_ItemClick(_In_ Object^ sender, _In_ ItemClickEventArg
|
|||
void HistoryList::OnDeleteMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
||||
{
|
||||
auto listViewItem = HistoryContextMenu->Target;
|
||||
auto itemViewModel = safe_cast<HistoryItemViewModel^>(HistoryListView->ItemFromContainer(listViewItem));
|
||||
|
||||
auto itemViewModel = dynamic_cast<HistoryItemViewModel^>(HistoryListView->ItemFromContainer(listViewItem));
|
||||
if (itemViewModel != nullptr)
|
||||
{
|
||||
Model->DeleteItem(itemViewModel);
|
||||
|
@ -65,10 +64,12 @@ void HistoryList::OnDeleteMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventA
|
|||
|
||||
void HistoryList::OnDeleteSwipeInvoked(_In_ MUXC::SwipeItem^ sender, _In_ MUXC::SwipeItemInvokedEventArgs^ e)
|
||||
{
|
||||
auto swipedItem = safe_cast<HistoryItemViewModel^>(e->SwipeControl->DataContext);
|
||||
|
||||
auto swipedItem = dynamic_cast<HistoryItemViewModel^>(e->SwipeControl->DataContext);
|
||||
if (swipedItem != nullptr)
|
||||
{
|
||||
Model->DeleteItem(swipedItem);
|
||||
}
|
||||
}
|
||||
|
||||
void HistoryList::ScrollToBottom()
|
||||
{
|
||||
|
|
|
@ -100,5 +100,5 @@ void Memory::IsErrorVisualState::set(bool value)
|
|||
MemoryItemViewModel^ Memory::GetMemoryItemForCurrentFlyout()
|
||||
{
|
||||
auto listViewItem = MemoryContextMenu->Target;
|
||||
return safe_cast<MemoryItemViewModel^>(MemoryListView->ItemFromContainer(listViewItem));
|
||||
return dynamic_cast<MemoryItemViewModel^>(MemoryListView->ItemFromContainer(listViewItem));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue