locked
Binding prevents page destruction

    Question

  • Hello!

    I have a problem in my application that, there is no page destruction after navigation to another page if first has binding to it's member:

    [Windows::Foundation::Metadata::WebHostHidden]
    	[Windows::UI::Xaml::Data::Bindable]
    	public ref class Test sealed : Windows::UI::Xaml::Data::INotifyPropertyChanged, public Windows::UI::Xaml::DependencyObject
    	{
    		event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ _privatePropertyChanged;
    	protected:
    		void OnPropertyChanged( Platform::String^ propertyName )
    		{
    			PropertyChanged( this, ref new Windows::UI::Xaml::Data::PropertyChangedEventArgs( propertyName ) );
    		}
    	public:
    		virtual event Windows::UI::Xaml::Data::PropertyChangedEventHandler^ PropertyChanged;
    		property Platform::String^ Name
    		{
    			Platform::String^ get() 
    			{
    				return (L"1111111");
    			}
    			void set(Platform::String^ value)
    			{
    				OnPropertyChanged(L"Name");
    			}
    		}
    		Test()
    		{
    
    		}
    
    		virtual ~Test()
    		{
    
    		}
    	};
    
    	/// <summary>
    	/// An empty page that can be used on its own or navigated to within a Frame.
    	/// </summary>
    	[Windows::UI::Xaml::Data::Bindable]
    	[Windows::Foundation::Metadata::WebHostHidden]
    	public ref class BlankPage sealed
    	{
    	public:
    		BlankPage();
    		virtual ~BlankPage();
    		property Test^ TestName;
    
    	protected:
    		virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
    	private:
    		void Button_Click_1(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
    	};

    In XAML file this page has next code statement, which binds text of textblock to member of this page BlankPage->TestName:

    <TextBlock HorizontalAlignment="Left" Margin="253,267,0,0" TextWrapping="Wrap" VerticalAlignment="Top"

    FontSize="20" Text="{Binding Path=TestName.Name, ElementName=mpNewPage}"/>

    Even if BlankPage->TestName has nullptr value (it had not been initialized yet) after navigation to next page destructor of BlankPage will not be called, which cases memory leaks. If  BlankPage->TestName had been initilized with some value it's destructor will not be called too.

    So, how can i avoid such situation and force destroying of all pages and controls which has internal binding?




    • Edited by texnedo Thursday, August 30, 2012 6:58 AM
    Thursday, August 30, 2012 6:57 AM

All replies