Tech Off Thread

12 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

WPF - Content of a page not showing

Back to Forum: Tech Off
  • User profile image
    WillemM

    I created this wonderful userinterface using the new page components in WPF and it worked great. Until suddenly the content doesn't show up anymore on one page.

    The page looks like this:

    <Page x:Class="WeSchedule247.RegisterAccountPage"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="WeSchedule247 - Register new account"
        >
      <Grid Margin="8,8,8,8">
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="100"/>
          <ColumnDefinition Width="150"/>
          <ColumnDefinition Width="*"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
          <RowDefinition Height="30"/>
          <RowDefinition Height="25"/>
          <RowDefinition Height="25"/>
          <RowDefinition Height="25"/>
          <RowDefinition Height="25"/>
          <RowDefinition Height="25"/>
          <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <TextBlock FontFamily="Arial" FontSize="16" Grid.Row="0" Grid.Column="0"
                   Grid.ColumnSpan="2">Register new account</TextBlock>
        <TextBlock Grid.Row="1" Grid.Column="0" Margin="2,2,2,2">
          Username:
        </TextBlock>
        <TextBox x:Name="UsernameTextBox" Grid.Row="1" Grid.Column="1"
                 Margin="2,2,2,2"></TextBox>
        <TextBlock Grid.Row="2" Grid.Column="0" Margin="2,2,2,2">
          E-mailaddress:
        </TextBlock>
        <TextBox x:Name="EmailTextBox" Grid.Row="2" Grid.Column="1"
                 Margin="2,2,2,2"></TextBox>
        <TextBlock Grid.Row="3" Grid.Column="0" Margin="2,2,2,2">
          Password:
        </TextBlock>
        <PasswordBox x:Name="PasswordTextBox1" Grid.Row="3" Grid.Column="1"
                 Margin="2,2,2,2"></PasswordBox>
        <TextBlock Grid.Row="4" Grid.Column="0" Margin="2,2,2,2">
          Confirm password:
        </TextBlock>
        <PasswordBox x:Name="PasswordTextBox2" Grid.Row="4" Grid.Column="1"
                 Margin="2,2,2,2"></PasswordBox>
        <Button x:Name="RegisterButton" Grid.Row="5" Grid.Column="0"
                Margin="2,2,2,2">Register</Button>
      </Grid>
    </Page>

    The page works in the designer, so you would think that it would work outside of the designer.

    Getting to the page is done by the following call:

    NavigationService.Navigate(new RegisterAccountPage());

    Anybody can shed some light on this one?

  • User profile image
    footballism

        I don't see any problem in the xaml file, probably there is something wrong with the code, so what's the navigator for the page, the NavigationWindow or Frame?

    Sheva

  • User profile image
    WillemM

    I use the page directly from App.xaml, which looks like this:

    <Application x:Class="WeSchedule247.App"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        StartupUri="LoginPage.xaml"
        >
        <Application.Resources>
            
        </Application.Resources>
    </Application>

  • User profile image
    footballism

        Then, it shouldn't have any problem here, could you please show us the code which you use to manipulate the xaml view, I don't think you just create the plain user interface and do nothing with it, don't you?

    Sheva

  • User profile image
    WillemM

    Hehe, well I don't do much with the user interface except for the following method attached to the register button on the RegisterAccountPage.

    private void RegisterButton_Click(object sender,EventArgs e)

    {

    UserManagementFacade model = new UserManagementFacade();

    if(PasswordTextBox1.Password == PasswordTextBox2.Password)

    {

    model.RegisterAccount(UsernameTextBox.Text,

    PasswordTextBox1.Password,

    EmailTextBox.Text);

    NavigationService.Navigate(new LoginPage());

    }

    else

    {

    }

    }

    This should be the problem though. I really don't know whats going on, but it sure is weird.
    So, yes I was building an almost empty UI, since most of the stuff was done behind the scene's in the business logic. Also, the user interface is far from complete, so I expected the trouble a little later than it is happening now Tongue Out

  • User profile image
    WillemM

    Hahaha, just found the bug. This line:

    InitializeComponent();

    was the source of all evil Tongue Out
    I removed it since the IDE was freaking out showing it with a red underline as if the line is broken, so I removed it.

    Added the line to the page codebehind again and all is functioning again. Man, they really need to do something about the IDE integration Tongue Out its all buggy, but then again, its beta.

  • User profile image
    footballism

        Hey, WillemM, Visual Studio 2005 doesn't treat the WPF  as its first citizen  in its design process, so that's why the integration between WPF and Visual Studio still have some problems, in particular, the debug of WPF applications using Visual Studio 2005 is so cumbersome, and is far from what we really expect,  future version of Visual Studio will be improved a lot in this respect, especially when the Cider designer is done.
        Actually you don't really need to write anything in the code-behind file to update the your data model based on the data you get from the registration UI, WPF's data binding is really powerful, and it is designed for such kinda of things, all you need to do is to have you data model class implementing INotifyPropertyChanged or INotifyCollectionChanged(if you are designing a collection)  interface. and in the xaml, you can use the BindingExtension to bind your UI elements with the data model from the back-end.

    Sheva

  • User profile image
    WillemM

    Thanks for the info, I am still in the early stages of using WPF. You know any good resources or books to learn more about databinding and WPF in general?

  • User profile image
    footballism

        Well, for data binding stuff, you should check Beatriz Costa's blog about data binding in WPF, I believe he's the guy inside Microsoft who implements those data binding goodness.
        And for book, Charles Petzold is pretty famous in the windows programming world, so is his book:

    Applications = Code + Markup


        But I rather prefer Ian Griffiths and Chris Sells's early release:

    Programming Windows Presentation Foundation

    Sheva

  • User profile image
    WillemM

    Thanks for the booktips, will ask my boss if I can buy one of those Smiley

  • User profile image
    bburkhart

    DataBinding is all powerful and good, but I just ran into an issue with the PasswordBox control...no data binding allowed on the Password property, since it's not a Dependency Property.

    Now, I'm ok with all the password security issues, but no data binding means no ValidationRules.  If you are building a form for creating new account, the ValidationRules are SO easy to use and create you own validators.  Building a RegexValidationRule that takes in a pattern is ideal for just about everything.  However, you can't use in on the PasswordBox, which totally sucks.  With Regex you could write patterns to validate complex password requirements.  Instead, I only see the option of validating on submit button click, or wire up to a TextChanged event and test it as the user types.  ??

    It would have been nice to allow data validation on the PasswordBox.Password property.

  • User profile image
    footballism

        PasswordBox.Password is designed as nomral CLR property for very good reason. if you can do binding on this property, there is a potential for security breach.

    Sheva

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.