locked
Creating WPF Application, XAML error RRS feed

  • Question

  • I'm taking a Microsoft Certified Virtual Lab. The exercise is to "Create a WPF Application"  I'm using Visual Studio 2005 in the Virtual Lab
      
            OK Step  1. After I created a new C# WPF  Project, I go to edit the Window1.xaml file.
            OK Step  2. I create <Grid.Resource> element and populate it with values
    NOT  OK Step  3. The next instruction is to add a <Style> element and populate it as follows.


    This is the exact wording of the lab tutorial:
     <Style x:Key="liStyle" Target Type="{x:Type ListBoxItem}"></Style>

    When I do this, I get the following error message:
    "Object Reference not set to an instance of the object".

     

     

    Questions:

    1. Why does the element as written generate the Error msg?

    2. How can I create a "Style" element with a Key of "liStyle" and a TargetType of "ListBoxItem" ?

     

    Thanks,

    LamarH

     

    Friday, April 9, 2010 4:32 PM

Answers

  • Jarrey:

     Thanks for the response:

    Here's what worked:

    Proper Syntax:
    <Grid.Resources>
    <Style x:Key="liStyle" TargetType="ListBoxItem"></Style>
    </Grid.Resources>

    Source: http://msdn.microsoft.com/en-us/library/ms750821.aspx

    Friday, April 9, 2010 7:21 PM

All replies

  • Hi,

    Please note the Bold word.

        <Grid>

        <Grid.Resources>

          <Style x:Key="liStyle" TargetType="{x:Type ListBoxItem}"></Style>

        </Grid.Resources>

      </Grid>


    Best day, Best life
    Friday, April 9, 2010 5:18 PM
  • Jarrey:

     Thanks for the response:

    Here's what worked:

    Proper Syntax:
    <Grid.Resources>
    <Style x:Key="liStyle" TargetType="ListBoxItem"></Style>
    </Grid.Resources>

    Source: http://msdn.microsoft.com/en-us/library/ms750821.aspx

    Friday, April 9, 2010 7:21 PM