Remote or Local XAML not working

Mar 27, 2012 at 10:15 AM

I just tried using the <Item> element to add some XAML content in the pivot. I was unable to do this with both local as well as remote XAML. In all cases, the XAML is being rendered as text with the first line highlighted.

Coordinator
Mar 27, 2012 at 10:43 AM

Did you follow the instructions on the Documentation page? You have to specify the "Type" attribute with a value of "xaml" explicitly for items that contain Xaml. A working example for remote Xaml is also contained in the sample application (download the source code for that); it pulls a Xaml file directly from CodePlex.

Mar 28, 2012 at 3:07 AM

Yes, In fact I copied pasted the code from your sample as well as documentation.  The XAML (when remote) downloads fine (or gives the fallback text if not found) correctly. But it's always rendered as text - with even the first line highlighted. Tried different spellings of xaml: xaml, Xaml, XAML. nothing worked.

Coordinator
Mar 28, 2012 at 7:59 AM

Can you copy your config and a sample Xaml that doesn't work here? I have used Xaml content (both local and remote) several times in projects. There shouldn't be any problems with it, so I suspect there's just a tiny mistake somewhere in the config/content.

Mar 29, 2012 at 4:29 AM

I tried the following:

      <Item Title="usage"
     Uri="http://localhost:4906/HelpUsage.xaml
            Type="xaml">
Network connection not found
 </Item>

Also, I tried it with inline XAML like this:

      <Item Title="usage"
            Type="xaml">

    <Grid>
        <StackPanel>
            <TextBlock Margin="0,10,0,10" TextWrapping="Wrap"  Text="This app lets you check the fare and stops in the routes for the Delhi Metro. Once the stations are loaded, tap on the text for the FROM and TO stations and select them from the list that pops up. Click the button to see the fare and the routes. Note that the route stops can be identified as follows." />
            <StackPanel Margin="0,2,0,2" Orientation="Horizontal">
                <Ellipse Width="30" Height="30" Fill="Green" />
                <TextBlock Text="Your starting station" />
            </StackPanel>
            <StackPanel Margin="0,2,0,2" Orientation="Horizontal">
                <Ellipse Width="30" Height="30" Fill="Yellow" />
                <TextBlock Text="Change your train here" />
            </StackPanel>
            <StackPanel Margin="0,2,0,2" Orientation="Horizontal">
                <Ellipse Width="30" Height="30" Fill="Blue" />
                <TextBlock Text="You will pass through this station" />
            </StackPanel>
            <StackPanel Margin="0,2,0,2" Orientation="Horizontal">
                <Ellipse Width="30" Height="30" Fill="Red" />
                <TextBlock Text="Your destination station" />
            </StackPanel>
        </StackPanel>
    </Grid>
</Item>

I also tried using it as a user control. THe Inline XAML was moved into a user control and it was referenced like this within the Item tag:

  <my:HelpUsage xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                   xmlns:my="clr-namespace:Delhi_Metro.Content.About;assembly=Delhi_Metro"
                   HorizontalAlignment="Stretch"
                   VerticalAlignment="Top" />

All of these ended up showing me the text rather than the XAML render.  

Coordinator
Apr 1, 2012 at 8:22 AM

Hi again. When you want to define XAML inline, the parser doesn't know what namespace to use. You have to explicitly declare that namespace. For example: your version doesn't work:

<Grid>
...
</Grid> 

But as soon as you add the correct namespace, it shows up as intended:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
...
</Grid>

When you add it as a user control, make sure that your user control works correctly in the same way (e.g. that the UserControl itself has all the required namespaces).

 

Apr 2, 2012 at 9:36 AM

Yup, the namespace was the issue.  working perfectly now. Thanks a TON!!