views:

394

answers:

1

I am writing an application in Silverlight that is supposed to retrieve weather data from Google and then display it. I was working on the layout in XAML and was going to see how it looked in the designer, but when I switched to the designer pane, a small notice said that an assembly had been updated, so I clicked it, and the user control vanished! I've been trying to remove parts of recent markup but it doesn't seem to help. Here is the XAML for the main user control:

<UserControl x:Class="TestApp2.Page"
 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
 xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
 xmlns:wtb="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Extended"
 xmlns:local="clr-namespace:TestApp2"
 Width="400" Height="300">

 <Grid x:Name="LayoutRoot" Background="#FF5e59e4">
  <Grid.RowDefinitions>
   <RowDefinition Height="*" />
  </Grid.RowDefinitions>
  <Grid.ColumnDefinitions>
   <ColumnDefinition Width="*" />
  </Grid.ColumnDefinitions>

  <Border Grid.Row="0" Grid.Column="0" Margin="5" CornerRadius="5" Background="AliceBlue">
   <Grid>
    <Grid.RowDefinitions>
     <RowDefinition Height="30" />
     <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
     <ColumnDefinition Width="*" />
     <ColumnDefinition Width="100" />
     <ColumnDefinition Width="70" />
    </Grid.ColumnDefinitions>

    <Border Grid.Row="0" Grid.Column="0" Margin="3" Style="{StaticResource RoundedBox}" >
     <TextBlock x:Name="TextBox" Text="Weather Finder" Margin="5,0,0,0" FontSize="18" VerticalAlignment="Center"/>
    </Border>
    <wtb:WatermarkedTextBox Grid.Row="0" Grid.Column="1" Watermark="City..." Margin="2,4,2,4" />
    <Button x:Name="SearchButton" Grid.Row="0" Grid.Column="3" Content="Search" VerticalAlignment="Center" Margin="2,0,2,0" />

    <!--<ListBox x:Name="DataList" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="3,0,3,3" />-->

    <StackPanel Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" Margin="3,0,3,3" Orientation="Vertical">
     <local:WeatherBox x:Name="Cur" HorizontalAlignment="Center" />

     <StackPanel Orientation="Horizontal">
      <local:WeatherBox x:Name="Day1" HorizontalAlignment="Center" />
      <local:WeatherBox x:Name="Day2" HorizontalAlignment="Center" />
      <local:WeatherBox x:Name="Day3" HorizontalAlignment="Center" />
      <local:WeatherBox x:Name="Day4" HorizontalAlignment="Center" />

     </StackPanel>
    </StackPanel>
   </Grid>
  </Border>

 </Grid>
</UserControl>

I have yet to write any functionality into the application, so that can't be the problem. I believe it might have something to do with my own WeatherBox (if anyone wants to see the code for it say so), but removing them from the code didn't work. What could be wrong?

I think I might have discovered one reason for the problems. This line of XAML in the WeatherBox control gets an exception when I run the application:

<BitmapImage UriSource="{Binding Thumbnail, Converter={StaticResource BitmapImageConverter}}" />

As far as I understood, it's not possible place use a binding directly in the UriSource, so I tried to use a converter. It seemed to work in the editor, but not when running. I still have no idea of what's wrong.

+1  A: 

This happens all the time with custom controls you design. At the moment the visual studio designer support is incredibly flaky (silverlight 2 & 3 beta with visual studio 2008). It will have a huff at the slightest of thing and will never tell you why. At least you're not getting the COM error.

The easiest way to find out the control that is causing it is to start commenting out swathes of your XAML until you identify the control by elimination.

Usually it will be one of your own controls and it will be doing it because you're trying to download some data from a website or web service, which it can't do in designer mode. All you need to do is detect if it's in design mode and skip the code if it is.

Here's a post abut detecting design mode: http://blogs.sqlxml.org/bryantlikes/archive/2009/02/25/detecting-design-mode-in-silverlight.aspx

The binding error isn't the cause, though it shouldn't be ignored. It means an object you've bound to doesn't have the property you're trying to access.

mattmanser
I already tried removing the WeatherBox controls from the main control, other than that I don't know what's causing it. I have yet to write the code that downloads weather data, so I'm stumped.
Bevin
I've commented out all of my Xaml except for the base grid, and it still doesn't work.
Bevin