Home > DeveloperSection > Forums > Loading XAML content without new window
Chintoo Semi

Total Post:135

Points:947
Posted on    September-25-2013 3:02 AM

 WPF WPF 
Ratings:


 1 Reply(s)
 733  View(s)
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



ezra heywood
ezra heywood

Total Post:145

Points:1019
Posted on    September-25-2013 4:25 AM

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

Don't want to miss updates? Please click the below button!

Follow MindStick