Click here to Skip to main content
16,022,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to put a page inside of a frame in code, it works fine when I call it from the main function. But when the button click event calls it, it does not change the frame's content. The frame within the page is already in a page in a frame if that has anything to do with it.

button click (gets called)
C#
public void Water_icon_MouseDown(object sender, MouseButtonEventArgs e)
{
    Popup_handler(Popup_type.Water);
}


the switch works how it's supposed to
C#
public void Popup_handler(Popup_type type)
{
    switch(type)
    {
        case Popup_type.Fertelizer:
            //Popup_frame.Content = new Popups.Fertilizer_popup(main_game);
            break;

        case Popup_type.Pest:
            //Popup_frame.Content = new Popups.Pest_popup(main_game);
            break;

        case Popup_type.Water:
            Popup_frame.Content = new Water_popup(main_game);
            break;

        case Popup_type.Air:
            //Popup_frame.Content = new Popups.Air_popup(main_game);
            break;

        case Popup_type.Light:
            //Popup_frame.Content = new Popups.Light_popup(main_game);
            break;
    }
}

Here's the frame, just in case:

XAML
<Frame x:Name="Popup_frame" Height="400" Grid.Row="1" 
       VerticalAlignment="Center" HorizontalAlignment="Right" 
       Width="1000" NavigationUIVisibility="Hidden"/>


What I have tried:

I checked the debugger and tested it separately, the page loads correctly and the inserted page works ok also. I tried the delegate because I thought it had to be something with threading, but it didn't work either. I have implemented something like this many times in this project already, but I never had this problem. Putting a different frame on the page doesn't work, changing the inserted page doesn't work either.
Posted

1 solution

Rather than using the MouseDown event, try using the MouseLeftButtonDown event instead and set e.Handled=true; immediately after the call to Popup_Handler.
 
Share this answer
 
Comments
George Swan 9-Jul-24 13:36pm    
I would suggest using PreviewMouseLeftButtonDown. It is a Tunnel event and they are more robust than bubble events.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900