Home All Groups Group Topic Archive Search About

Can't access a System object in xaml

Author
15 Nov 2007 3:58 PM
BBM
Hi,

I have this xaml code that I'm trying to use in a Window...

<ListBox xmlns:sys="clr-namespace:System;assembly=mscorlib" Grid.Column="2"
Grid.RowSpan="2">
      <Button>Click for a surprise</Button>
      <Expander>
        Details
        <StackPanel>
          <sys:DateTime>1/1/2007</sys:DateTime>
          <sys:DateTime>2/1/2007</sys:DateTime>
          <sys:DateTime>3/1/2007</sys:DateTime>
        </StackPanel>
      </Expander>
    </ListBox>

The problem is with the <sys:DateTime> elements.  I get a compiler warning
on these saying that StackPanel has "invalid" child elements.  The code will
not run.

If I put the <sys:DateTime> elements directly under the listbox (eliminating
the button and the expander), I get the same warning, but the code will run
and show the date correctly.

I'm using VS2005 with .Net 3.0 installed.

Why isn't <sys:DateTime> recognized?  What am I doing wrong here?

BBM

Author
16 Nov 2007 3:09 AM
Walter Wang [MSFT]
Hi BBM,

The StackPanel can only use UIElement as child elements. You can use a
ListBox instead:

                <StackPanel>
                    <ListBox>
                        <sys:DateTime>1/1/2007</sys:DateTime>
                        <sys:DateTime>2/1/2007</sys:DateTime>
                        <sys:DateTime>3/1/2007</sys:DateTime>
                    </ListBox>
                </StackPanel>


Hope this helps.



Regards,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
16 Nov 2007 3:59 PM
BBM
Hi Walter,

Thanks for your response.  What you suggested works, but I still get an
"invalid child" compiler warning on the DateTime element when it is the child
of a ListBox.  Clearly it (DateTime) has a 'To String' representation so I
don't see why it would be considered "invalid".

Also, is there some place I can go (other than to the individual class
documentation) that shows what classes can be children of other classes?

Thanks.

""Walter Wang [MSFT]"" wrote:

Show quote
> Hi BBM,
>
> The StackPanel can only use UIElement as child elements. You can use a
> ListBox instead:
>
>                 <StackPanel>
>                     <ListBox>
>                         <sys:DateTime>1/1/2007</sys:DateTime>
>                         <sys:DateTime>2/1/2007</sys:DateTime>
>                         <sys:DateTime>3/1/2007</sys:DateTime>
>                     </ListBox>
>                 </StackPanel>
>
>
> Hope this helps.
>
>
>
> Regards,
> Walter Wang (waw***@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
Author
21 Nov 2007 2:56 AM
Walter Wang [MSFT]
Hi BBM,

I'm writing to check the status of this post. Please feel free to let me
know if there's anything else I can help. Thanks.

Regards,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
21 Nov 2007 4:03 AM
BBM
Hi Walter,

I got my code to work using your suggestions, but
could you answer my last questions?

1)  Is it normal to get compiler warnings on the direct use of .Net classes
(like DateTime) from xaml?   If so, why?

2)  Is there a (concise) place where I can learn what items can be
"children" of other items in WPF?

Thanks.
""Walter Wang [MSFT]"" wrote:

Show quote
> Hi BBM,
>
> I'm writing to check the status of this post. Please feel free to let me
> know if there's anything else I can help. Thanks.
>
> Regards,
> Walter Wang (waw***@online.microsoft.com, remove 'online.')
> Microsoft Online Community Support
>
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
Author
21 Nov 2007 9:51 AM
Walter Wang [MSFT]
Hi BBM,

1) I'm using VS2008 RTM and I don't see warnings when using CLR types in
xaml.

2) Please refer to following MSDN document:

#Content Models
http://msdn2.microsoft.com/en-us/library/ms751553.aspx

The ListBox is using ItemsControl Content Model while the StackPanel is
using Panel Content Model; different content models can use different
content.

Hope this helps.


Regards,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
Author
26 Nov 2007 3:03 AM
Walter Wang [MSFT]
Hi BBM,

I'm writing to check the status of this post. Please feel free to let me
know if there's anything else I can help. Thanks.

Regards,
Walter Wang (waw***@online.microsoft.com, remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

AddThis Social Bookmark Button