Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't new WPF Windows I create inheriting from Window?

When I create a new Window, using the Add Item... dialogue, the Window I create, e.g. NewWindow, does not inherit from Window. It only has the same interface as type Object. An example:

I have the popup window code below. The code only sees the IHavePassword members, and not the rest of the members of `LoginPopup', like its controls.

Public Class LoginPopup
    Implements IHavePassword

    Public ReadOnly Property Password As SecureString Implements IHavePassword.Password
        Get
            'Return Me.PasswordBox.????
        End Get
    End Property

    Public Event PasswordChanged As RoutedEventHandler Implements IHavePassword.PasswordChanged
    Public Sub PassWordChangedHandler(sender As Object, e As EventArgs)
        PasswordChangedEvent(sender, e)
    End Sub

    Public Sub Close() Implements IHavePassword.Close
        Throw New NotImplementedException
    End Sub

End Class

OH, here is the necessary XAML as well:

<Window x:Class="ApptEase.Client.Prism.Views.LoginPopup"
....
<StackPanel Orientation="Vertical" Margin="0">
    <DockPanel LastChildFill="True">
        <TextBlock Text="{Binding Path=UsernameLabel}" DockPanel.Dock="Left" TextAlignment="Right" Margin="5,9,5,5" MinWidth="70" />
        <TextBox Text="{Binding Path=Username, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" Width="Auto" Margin="5" />
    </DockPanel>
    <DockPanel LastChildFill="True">
        <TextBlock Text="{Binding Path=PasswordLabel}" DockPanel.Dock="Left" TextAlignment="Right" Margin="5" MinWidth="70" />
        <PasswordBox x:Name="PasswordBox" PasswordChanged="PassWordChangedHandler" Width="Auto" Margin="5" />
    </DockPanel>
    <DockPanel LastChildFill="True" Height="59">
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Content="Log in" Command="{Binding Path=LoginCommand}" CommandParameter="{Binding ElementName=This}" Margin="5" Padding="15,10,15,10" />
            <Button Content="Cancel" Command="{Binding Path=CancelCommand}" CommandParameter="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" Margin="5" Padding="15,10,15,10"/>
        </StackPanel>
    </DockPanel>
</StackPanel>

The IntelliSense on the property Me lists the members of IHavePassword, e.g:

enter image description here

I would expect to see the controls and base Window members here, not those of the interface. How do I go about fixing this?

like image 323
ProfK Avatar asked Oct 24 '16 10:10

ProfK


People also ask

How do I switch between windows in WPF?

NavigationService is for browser navigation within WPF. What you are trying to do is change to a different window TrainingFrm . To go to a different window, you should do this: private void conditioningBtn_Click(object sender, RoutedEventArgs e) { var newForm = new TrainingFrm(); //create your new form.

What is the difference between a page and a window in WPF when you are adding a new file in the Solution Explorer?

Window is the root control that must be used to hold/host other controls (e.g. Button) as container. Page is a control which can be hosted in other container controls like NavigationWindow or Frame. Page control has its own goal to serve like other controls (e.g. Button). Page is to create browser like applications.

How do you call a window in WPF?

Step 1: Create an empty WPF using Visual Studio, enter the name for the application and click on OK. Step 2: Create a button using the following code or drag and drop a button from the ToolBox of Visual Studio 2013.


1 Answers

I think you just forgot to surround the class with your namespace:

Namespace ApptEase.Client.Prism.Views
    Public Class LoginPopup
        Implements IHavePassword

        '...

    End Class
End Namespace
like image 192
haindl Avatar answered Oct 12 '22 23:10

haindl