LOADING XAML CONTENT WITHOUT NEW WINDOW

Chintoo Semi

Total Post:135

Points:947
Posted by  Chintoo Semi
WPF 
WPF
 1008  View(s)
Ratings:
Rate this:

I'm trying to find a way to change the content of a window in WPF without having to load a new window. In most cases, the following works just fine:

dim x as new window

x.show()

me.close

Is there a way to do something like the following?

dim x as new window

me.content = x

  1. ezra heywood

    Post:145

    Points:1019
    Re: Loading XAML content without new window

    Hi Chintoo,

    The window I used this in is being used with a barcode scanner. We have a handful of item types that can be scanned with a different set of options and displays needed for each. Since our app is written in the MVVM pattern (Or at least... MVVM-esque ;) ) I created some XAML:

    <ContentControl Grid.Row="2" Content="{Binding itemOptions}" />

    Which is then bound to this property:

        Public ReadOnly Property itemOptions As UserControl

            Get

                Select Case SearchResult.GetType()

                    ' Part

                    Case GetType(partHeaderModel)

                        Try

                            Return New partOptions

                        Catch ex As Exception

                            ' Fail

                            ' Return New noResults

                        End Try

                        ' Bin

                    Case GetType(binModel)

                        Try

                            Return New binOptions

                        Catch ex As Exception

                            ' Fail

                            Return New noResults

                        End Try

                        ' Rack

                    Case GetType(rackModel)

                        Try

                            Return New rackOptions

                        Catch ex As Exception

                            ' Fail

                            Return New noResults

                        End Try

                    Case Else

                End Select

                Return New noResults

            End Get

        End Property

    I have a search function which returns a data model based on the type of item the user scans. Based on the type, the select statement returns the property user control. I use INotifyPropertyChanged along with the scan event to get the window to update.

      Modified On Apr-04-2016 10:55:01 PM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!