2010-03-05 57 views
2

我遇到以下Silverlight 2中出現的問題;在Silverlight 3中,相同的代碼工作正常。Silverlight 2:Silverlight 2中的XamlParseException

的XAML代碼如下:

<UserControl x:Class="My_Discussions.ThreadListItem" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows" 
xmlns:discussion="clr-namespace:My_Discussions" 
Width="Auto" Height="Auto">  

<UserControl.Resources> 

    <ControlTemplate x:Key="TopicItem"> 
     <Grid x:Name="TopicItemHost" ShowGridLines="False" Margin="0,8" VerticalAlignment="Stretch"> 
      <vsm:VisualStateManager.VisualStateGroups> 
       <vsm:VisualStateGroup x:Name="CommonStates"> 
        <vsm:VisualState x:Name="Normal" /> 
        <vsm:VisualState x:Name="MouseOver"> 
         <Storyboard> 
          <DoubleAnimation 
            Storyboard.TargetName="hotRect" 
            Storyboard.TargetProperty="Opacity" 
            Duration="0" 
            To="1" /> 
          <ObjectAnimationUsingKeyFrames 
           Storyboard.TargetName="TopicItemHost" 
           Storyboard.TargetProperty="Cursor" 
           Duration="0"> 
           <DiscreteObjectKeyFrame KeyTime="0"> 
            <DiscreteObjectKeyFrame.Value> 
             <Cursors>Hand</Cursors> 
            </DiscreteObjectKeyFrame.Value> 
           </DiscreteObjectKeyFrame> 
          </ObjectAnimationUsingKeyFrames> 
         </Storyboard> 
        </vsm:VisualState> 
       </vsm:VisualStateGroup> 
       <vsm:VisualStateGroup x:Name="FocusStates"> 
        <vsm:VisualState x:Name="Unfocused" /> 
        <vsm:VisualState x:Name="Focused"> 
         <Storyboard> 
          <DoubleAnimation 
            Storyboard.TargetName="focusRect" 
            Storyboard.TargetProperty="Opacity" 
            Duration="0" 
            To="1" /> 
         </Storyboard> 
        </vsm:VisualState> 
       </vsm:VisualStateGroup> 
       <vsm:VisualStateGroup x:Name="ReadUnreadStates"> 
        <vsm:VisualState x:Name="Read" /> 
        <vsm:VisualState x:Name="Unread"> 
         <Storyboard> 
          <ObjectAnimationUsingKeyFrames 
           Storyboard.TargetName="TopicTitle" 
           Storyboard.TargetProperty="FontWeight" 
           Duration="0"> 
           <DiscreteObjectKeyFrame KeyTime="0"> 
            <DiscreteObjectKeyFrame.Value> 
             <FontWeight>Bold</FontWeight> 
            </DiscreteObjectKeyFrame.Value> 
           </DiscreteObjectKeyFrame> 
          </ObjectAnimationUsingKeyFrames> 
         </Storyboard> 
        </vsm:VisualState> 
       </vsm:VisualStateGroup> 
      </vsm:VisualStateManager.VisualStateGroups> 

      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto" MinWidth="10"/> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 

      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto" /> 
       <RowDefinition Height="*" /> 
      </Grid.RowDefinitions> 

      <Rectangle x:Name="focusRect" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="2" Fill="#F0F0F0" Margin="0,-8" Opacity="0"/> 
      <Rectangle x:Name="hotRect" Grid.Column="1" Height="1" Margin="0,0,0,0" VerticalAlignment="Bottom" Opacity="0" 
         > 
       <Rectangle.Fill> 
        <LinearGradientBrush StartPoint="0,0" EndPoint="1,0"> 
         <GradientStop Color="#4080C0" Offset="0" /> 
         <GradientStop Color="Gray" Offset="0.5" /> 
         <GradientStop Color="White" Offset="1" /> 
        </LinearGradientBrush> 
       </Rectangle.Fill> 
      </Rectangle> 

      <Image x:Name="TopicLock" Grid.Column="0" Visibility="Collapsed" 
        Stretch="None" Source="Images/locked.png" Margin="10,2,10,0" 
        VerticalAlignment="Top" /> 

      <discussion:ThreadListItemTitleHost Grid.Column="1" 
               HorizontalAlignment="Left" 
               VerticalAlignment="Stretch"> 
       <discussion:TextCut x:Name="TopicTitle" 
            Padding="0,0" 
            Foreground="#4080C0" 
            HorizontalAlignment="Left" 
            VerticalAlignment="Top"/> 

       <discussion:TextCut x:Name="TopicBody" 
            Padding="4,0" 
            VerticalAlignment="Top" 
            HorizontalAlignment="Left" 
            Foreground="Gray"/> 
      </discussion:ThreadListItemTitleHost> 

     </Grid> 
    </ControlTemplate> 

    <ControlTemplate x:Key="ProjectItem"> 
     <TextBlock x:Name="Project" Padding="10,8" VerticalAlignment="Top" TextWrapping="Wrap"/> 
    </ControlTemplate> 

    <ControlTemplate x:Key="MessagesItem"> 
     <TextBlock x:Name="Messages" Padding="10,8" VerticalAlignment="Top"/> 
    </ControlTemplate> 

    <ControlTemplate x:Key="AuthorItem"> 
     <discussion:TextCut x:Name="Author" Padding="10,8" VerticalAlignment="Top" HorizontalAlignment="Stretch"/> 
    </ControlTemplate> 

    <ControlTemplate x:Key="DateItem"> 
     <TextBlock x:Name="Date" Padding="10,8" VerticalAlignment="Top" /> 
    </ControlTemplate> 

    <ControlTemplate x:Key="BottomBorder"> 
     <Rectangle Width="Auto" Height="0.5" VerticalAlignment="Bottom" Stroke="Gray" StrokeThickness="0.5" /> 
    </ControlTemplate> 

</UserControl.Resources> 

所以,有一個名爲 「TopicTitle」 中的XAML控制。類TextCut實現該控件包含屬性 「fontWeight設置」:

public static readonly DependencyProperty FontWeightProperty = DependencyProperty.RegisterAttached(
     "FontWeight", 
     typeof(FontWeight), 
     typeof(TextCut), 
     new PropertyMetadata(new PropertyChangedCallback(OnFontWeightPropertyChanged))); 

然後,我稱之爲 「VisualStateManager.GoToState(CTRL 」未讀「,FALSE)」。此調用應將值粗體設置爲控件「TopicTitle」的屬性「FontWeight」。

Silverlight的2.0以下例外情況:

XamlParseException: LineNumber上:0 LinePosition:0 消息: 「[行:0位置:0]」 調用堆棧是: MS.Internal。 XcpImports.CheckHResult(UInt32的小時) 在MS.Internal.XcpImports.Storyboard_SeekAlignedToLastTick(故事板故事板,一seekTime) 在System.Windows.Media.Animation.Storyboard.SeekAlignedToLastTick(時間跨度偏移) 在System.Windows.VisualStateGroup.StartNewThenStopOld( FrameworkElement元素,Storyboard [] newStoryboards) 在System.Windows.VisualStateManager.GoToStateInternal(控制控制,FrameworkElement的元件,VisualStateGroup基,的VisualState狀態,布爾useTransitions) 在System.Windows.VisualStateManager.GoToState(控制控制,字符串Statename的,布爾useTransitions)

Silverlight的3.0,正如我所說,沒有問題。問題是:Silverlight 2.0發生了什麼,以及如何避免這種情況?什麼是「[Line:0 Position:0]」 - 它沒有告訴我。

<FontWeight>Bold</FontWeight> 

我敢肯定,你必須有很好的理由與SL2堅持,但 - :

回答

0

那麼我的Silverlight 2的知識是很生疏,但看着調用堆棧我想說它得到這個心煩我不禁要說明,可能的解決辦法是使用SL3。

+0

謝謝你的回答。 ' Bold' - 這可能是錯誤的?我嘗試將相同的代碼應用於TextBlock控件,而不是如果我的自定義控件 - 並且這起作用:文本變爲粗體。 – KellyLynch 2010-03-06 09:52:57