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">
|
<DataTemplate x:Key="HistoryItemTemplate" x:DataType="model:HistoryItemViewModel">
|
||||||
<muxc:SwipeControl RightItems="{StaticResource HistorySwipeItems}">
|
<muxc:SwipeControl RightItems="{StaticResource HistorySwipeItems}">
|
||||||
<StackPanel Margin="0,6,4,6"
|
<StackPanel Margin="0,6,4,6" Background="Transparent">
|
||||||
Background="Transparent">
|
|
||||||
<TextBlock x:Name="ExprTextBlock"
|
<TextBlock x:Name="ExprTextBlock"
|
||||||
Margin="0,0,0,4"
|
Margin="0,0,0,4"
|
||||||
HorizontalAlignment="Right"
|
HorizontalAlignment="Right"
|
||||||
|
|
|
@ -42,11 +42,11 @@ HistoryList::HistoryList()
|
||||||
|
|
||||||
void HistoryList::ListView_ItemClick(_In_ Object^ sender, _In_ ItemClickEventArgs^ e)
|
void HistoryList::ListView_ItemClick(_In_ Object^ sender, _In_ ItemClickEventArgs^ e)
|
||||||
{
|
{
|
||||||
HistoryViewModel^ historyVM = static_cast<HistoryViewModel^>(this->DataContext);
|
HistoryViewModel^ historyVM = dynamic_cast<HistoryViewModel^>(this->DataContext);
|
||||||
HistoryItemViewModel^ clickedItem = safe_cast<HistoryItemViewModel^>(e->ClickedItem);
|
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
|
// 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);
|
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)
|
void HistoryList::OnDeleteMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventArgs^ e)
|
||||||
{
|
{
|
||||||
auto listViewItem = HistoryContextMenu->Target;
|
auto listViewItem = HistoryContextMenu->Target;
|
||||||
auto itemViewModel = safe_cast<HistoryItemViewModel^>(HistoryListView->ItemFromContainer(listViewItem));
|
auto itemViewModel = dynamic_cast<HistoryItemViewModel^>(HistoryListView->ItemFromContainer(listViewItem));
|
||||||
|
|
||||||
if (itemViewModel != nullptr)
|
if (itemViewModel != nullptr)
|
||||||
{
|
{
|
||||||
Model->DeleteItem(itemViewModel);
|
Model->DeleteItem(itemViewModel);
|
||||||
|
@ -65,9 +64,11 @@ void HistoryList::OnDeleteMenuItemClicked(_In_ Object^ sender, _In_ RoutedEventA
|
||||||
|
|
||||||
void HistoryList::OnDeleteSwipeInvoked(_In_ MUXC::SwipeItem^ sender, _In_ MUXC::SwipeItemInvokedEventArgs^ e)
|
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);
|
Model->DeleteItem(swipedItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HistoryList::ScrollToBottom()
|
void HistoryList::ScrollToBottom()
|
||||||
|
|
|
@ -100,5 +100,5 @@ void Memory::IsErrorVisualState::set(bool value)
|
||||||
MemoryItemViewModel^ Memory::GetMemoryItemForCurrentFlyout()
|
MemoryItemViewModel^ Memory::GetMemoryItemForCurrentFlyout()
|
||||||
{
|
{
|
||||||
auto listViewItem = MemoryContextMenu->Target;
|
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