Why aren't the new WPF windows that I create inherit from the window?

When I create a new window using the "Add Element ..." dialog, the created Window, for example. NewWindow , not inherited from Window. It has only the same interface as the Object type. Example:

I have a popup window code below. The code sees only members of IHavePassword , and not the rest of the LoginPopup members, 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, XAML is also required here:

 <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> 

IntelliSense for the Me property lists IHavePassword members, for example:

enter image description here

I would expect to see the controls and base members of Window , not those that have an interface. How can i fix this?

+6
source share
4 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 
+4
source

To be sure, in your comments, you said that LoginPopup is a partial class, but you do not have a "Partial statement" in your code. I am primarily a C # developer, so I’m not sure, but should not be there "Partial Public LoginPopup"?

+1
source

To answer the question asked.

Add a new "Window ..." instead of using "Add Element ..." and create a new generic class. Then add your code.

+1
source

First, it has nothing to do with partial classes or inherits from Window , as suggested in many comments. The item template for the VB WPF window takes care of all this; we stopped the "manual coding" of windows and user interface elements a very long time ago.

Then I refused to find out what caused this, except, most likely, a project file or VS, dysfunctional. I created a new VB WPF project, and in this case, when I add a new Window , everything is fine, i.e. Inheritance is true.

0
source

Source: https://habr.com/ru/post/1011648/


All Articles