2017-01-24 57 views
0

我試圖將WP8 projet轉換爲Universal Apps。我正在嘗試關於LocalizedStrings的一個奇怪的錯誤。VS2015 Universal Project中無法識別的LocalizedStrings

我使用多語言應用程序工具包來管理翻譯。我已更新到支持通用應用的最新版本(4.0)。

事情是它在App.xaml中給我這個錯誤:命名空間「using:StayfilmUniversalApp」中不存在名稱「LocalizedStrings」。

,它是在其他網頁太多,但不是在抱怨上MainPage.xaml中...... 在MainPage.xaml中它說,類型LocalizedStrings沒有被發現。顏色爲藍色強調,有一個使用LocalizedStrings,對於如:

<DataTemplate x:Key="TIT_WhatsNew"> 
     <Grid Width="250" Height="52" Margin="0" HorizontalAlignment="Left"> 
      <Rectangle Fill="White" HorizontalAlignment="Left" Height="3" Margin="0" VerticalAlignment="Top" Width="250" /> 
      <TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="{Binding LocalizedResources.WHATSNEW, Mode=OneWay, Source={StaticResource LocalizedStrings}}" VerticalAlignment="Center" FontSize="21.333" FontStretch="ExtraCondensed" FontFamily="/Assets/Fonts/Frontage-regular.otf#Frontage Regular" /> 
      <Rectangle Fill="White" HorizontalAlignment="Left" Height="3" Margin="0" VerticalAlignment="Bottom" Width="250" /> 
     </Grid> 
    </DataTemplate> 

,這裏是我的App.xaml組件整體的DataTemplate塊:

<Application 
x:Class="StayfilmUniversalApp.App" 
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
xmlns:local="using:StayfilmUniversalApp" 
RequestedTheme="Light"> 

<Application.Resources> 
    <ResourceDictionary> 
     <!--<local:LocalizedStrings x:Key="LocalizedStrings"/>--> 
     <local:LocalizedStrings xmlns:local="using:StayfilmUniversalApp" x:Key="LocalizedStrings" /> 
     <Color x:Key="PhoneDisabledColor">#66FFFFFF</Color> 
     <SolidColorBrush x:Key="PhoneDisabledBrush" Color="{StaticResource PhoneDisabledColor}" /> 
     <ResourceDictionary.MergedDictionaries> 
      <ResourceDictionary Source="Styles\PhoneStyles.xaml" /> 
     </ResourceDictionary.MergedDictionaries> 
     <!-- Other resources if you have --> 
    </ResourceDictionary> 
</Application.Resources> 

和我LocalizedStrings。 cs:

using StayfilmUniversalApp.Resources; 

namespace StayfilmUniversalApp 
{ 
    /// <summary> 
    /// Provides access to string resources. 
    /// </summary> 
    public class LocalizedStrings 
    { 
     private static AppResources _localizedResources = new AppResources(); 

     public AppResources LocalizedResources { get { return _localizedResources; } } 
    } 
} 
+0

的「本地」命名空間的定義似乎是畸形的,看看這個:https://msdn.microsoft.com /en-us/library/ms747086(v=vs.110).aspx – Gusman

+0

我嘗試過使用clr-namespace,但它也不能工作。我讀過的地方是'通用應用程序'中'clr-namespace'被替換爲'using'。還有什麼更奇怪的是,所有其他頁面識別LocalizedString – rickrvo

+0

好吧,我已經清理緩存... \ AppData \ Local \ Microsoft \ Phone Tools \ CoreCon \ 12.0,現在所有頁面都不識別LocalizedStrings ... – rickrvo

回答

0

該問題與Locali無關zedStrings。

我放棄了試圖修復該頁面,並決定從頭開始重新創建它。這樣做,我發現後面可能有一個VS錯誤,並顯示不同的錯誤。因爲當我將一個DataTemplate(下面這個)添加到HubSection時,它在整個DataTemplate塊上給我提供了這個錯誤: 無法將類型'Windows.UI.Xaml.Setter'的實例添加到'Windows.UI'類型的集合中。 Xaml.SetterBaseCollection」。

<DataTemplate x:Key="YOTWDataTemplate"> 
     <ScrollViewer HorizontalAlignment="Left" VerticalAlignment="Top" BorderThickness="0" Height="548"> 
       <StackPanel x:Name="stackYOTW" Margin="0,0,0,100" HorizontalAlignment="Center" VerticalAlignment="Top" Width="420"> 
        <TextBlock TextWrapping="Wrap" Foreground="White" FontFamily="Portable User Interface" Margin="12,0,0,0"> 
         <Run Text="{Binding LocalizedResources.EveryWeek, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/> 
         <Run FontWeight="Bold" Text="YES!"/> 
         <LineBreak/> 
         <Run Text="{Binding LocalizedResources.ChoosenByStayfilm, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/> 
         <LineBreak/> 
         <Run Text="{Binding LocalizedResources.ForYouToWatch, Mode=OneWay, Source={StaticResource LocalizedStrings}}"/> 
        </TextBlock> 
        <ListBox x:Name="listYOTW" ItemsSource="{Binding listYesMovie}" Foreground="White" Background="{x:Null}" BorderBrush="{x:Null}" ScrollViewer.VerticalScrollBarVisibility="Disabled"> 
         <ListBox.ItemTemplate> 
          <DataTemplate> 
           <Grid Margin="12,20,0,0" Background="White" Width="420"> 
            <Grid.ColumnDefinitions> 
             <ColumnDefinition Width="64"/> 
             <ColumnDefinition/> 
            </Grid.ColumnDefinitions> 
            <Grid.RowDefinitions> 
             <RowDefinition Height="64*"/> 
             <RowDefinition Height="119*"/> 
             <RowDefinition Height="50*"/> 
            </Grid.RowDefinitions> 
            <Image Margin="12" Source="{Binding user.photo}" VerticalAlignment="Center" Width="40" Height="40" HorizontalAlignment="Center" Stretch="Fill"/> 
            <TextBlock x:Name="NAME" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Semibold" Margin="0" Grid.Column="1" Foreground="#FFAF252B" Text="{Binding user.fullName}" FontSize="18.667"/> 
            <TextBlock x:Name="TIME" HorizontalAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,0,14,0" Grid.Column="1" Foreground="#FF787878" Text="{Binding prettyPublicated}" FontSize="17.333" TextAlignment="Right"/> 
            <Image Grid.ColumnSpan="2" Margin="0,0,0,59" Grid.RowSpan="2" Source="{Binding thumbnailUrl}" Stretch="UniformToFill" Grid.Row="1"/> 
            <Grid x:Name="TituloFILM" Grid.ColumnSpan="2" Height="50" VerticalAlignment="Top" Grid.Row="1" Background="#CCAF252B"> 
             <TextBlock x:Name="TITLE" HorizontalAlignment="Left" TextWrapping="Wrap" Text="{Binding title}" VerticalAlignment="Center" Foreground="White" FontFamily="Segoe WP Light" FontSize="24" Margin="14,0,0,0"/> 
            </Grid> 
            <Grid x:Name="GridYES" Grid.ColumnSpan="2" HorizontalAlignment="Left" Grid.RowSpan="2" VerticalAlignment="Bottom" Width="80" Grid.Row="2" Height="30" Margin="14"> 
             <Canvas x:Name="iconYES" HorizontalAlignment="Right" Height="20" UseLayoutRounding="False" VerticalAlignment="Center" Width="46" Margin="0"> 
              <Canvas x:Name="Layer_1" Height="15.391" Canvas.Left="0.409" Canvas.Top="2.304" Width="45.182"> 
               <Path Data="F1M10.991,0L7.327,5.987 3.619,0 0,0 5.741,8.801 5.741,14.9 8.913,14.9 8.913,8.801 14.61,0z" Fill="#FF9AA7B2" Height="14.9" Canvas.Left="0" Canvas.Top="0.223" Width="14.61"/> 
               <Path Data="F1M0,14.901L0,0 10.544,0 10.544,2.793 3.172,2.793 3.172,5.943 10.388,5.943 10.388,8.734 3.172,8.734 3.172,12.109 10.544,12.109 10.544,14.901z" Fill="#FF9AA7B2" Height="14.901" Canvas.Left="15.552" Canvas.Top="0.223" Width="10.544"/> 
               <Path Data="F1M0,13.024L1.72,10.611C2.77,11.706 4.4,12.622 6.457,12.622 8.199,12.622 9.046,11.817 9.046,10.968 9.046,8.332 0.469,10.142 0.469,4.534 0.469,2.055 2.613,0 6.121,0 8.489,0 10.455,0.715 11.929,2.077L10.164,4.4C8.958,3.283 7.349,2.77 5.83,2.77 4.468,2.77 3.708,3.373 3.708,4.267 3.708,6.635 12.263,5.048 12.263,10.611 12.263,13.336 10.32,15.391 6.299,15.391 3.44,15.391 1.384,14.431 0,13.024" Fill="#FF9AA7B2" Height="15.391" Canvas.Left="27.575" Canvas.Top="0" Width="12.263"/> 
               <Path Data="F1M0.537,10.053L0.067,0 3.485,0 3.039,10.053z M0,13.337C0,12.354 0.805,11.528 1.787,11.528 2.77,11.528 3.598,12.354 3.598,13.337 3.598,14.297 2.77,15.124 1.787,15.124 0.805,15.124 0,14.297 0,13.337" Fill="#FF9AA7B2" Height="15.124" Canvas.Left="41.584" Canvas.Top="0.223" Width="3.598"/> 
              </Canvas> 
             </Canvas> 

             <TextBlock x:Name="N_YES" HorizontalAlignment="Right" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,0,59,3" Foreground="#FF35424D" Text="{Binding likeCount}" FontSize="20" TextAlignment="Right"/> 
            </Grid> 
            <Grid x:Name="GridCOMENT" Grid.ColumnSpan="2" HorizontalAlignment="Center" VerticalAlignment="Bottom" Width="70" Grid.Row="2" Height="30" Margin="14"> 
             <Canvas x:Name="iconCOMENT" HorizontalAlignment="Right" Height="26" UseLayoutRounding="False" VerticalAlignment="Center" Width="28" Margin="0,2,0,0"> 
              <Canvas x:Name="Layer_4" Height="22.194" Canvas.Left="2.697" Canvas.Top="1.903" Width="22.605"> 
               <Path Data="M23.106,0.5L0.5,0.5 0.5,16.001 6.216,16.001 3.852,22.694 13.176,16.001 23.106,16.001z" Height="24.028" Canvas.Left="-0.5" Stroke="#FF9BA8B3" Canvas.Top="-0.5" Width="23.605"/> 
              </Canvas> 
             </Canvas> 

             <TextBlock x:Name="N_YES1" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,-3,0,0" Foreground="#FF35424D" Text="{Binding commentCount}" FontSize="20" TextAlignment="Right"/> 
            </Grid> 
            <Grid x:Name="GridVIEW" Grid.ColumnSpan="2" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="70" Grid.Row="2" Height="30" Margin="14"> 

             <Canvas x:Name="iconVIEW" HorizontalAlignment="Right" Height="26" UseLayoutRounding="False" VerticalAlignment="Center" Width="36"> 
              <Canvas x:Name="Layer_2" Height="18" Canvas.Left="2.113" Canvas.Top="4" Width="31.145"> 
               <Path Data="M31.723,9.5C28.609,4.125 22.809,0.5 16.151,0.5 9.492,0.5 3.692,4.125 0.578,9.5 3.692,14.875 9.492,18.5 16.151,18.5 22.809,18.5 28.609,14.875 31.723,9.5z" Height="19" Canvas.Left="-0.578" Stroke="#FF9BA8B3" Canvas.Top="-0.5" Width="32.301"/> 
               <Path Data="F1M9.409,4.705C9.409,7.303 7.303,9.41 4.704,9.41 2.106,9.41 0,7.303 0,4.705 0,2.107 2.106,0 4.704,0 7.303,0 9.409,2.107 9.409,4.705" Fill="#FF9BA8B3" Height="9.41" Canvas.Left="10.868" Canvas.Top="4.295" Width="9.409"/> 
              </Canvas> 
             </Canvas> 

             <TextBlock x:Name="N_YES2" HorizontalAlignment="Left" TextWrapping="Wrap" VerticalAlignment="Center" FontFamily="Segoe WP Light" Margin="0,-3,0,0" Foreground="#FF35424D" Text="{Binding viewCount}" FontSize="20" TextAlignment="Right"/> 
            </Grid> 
            <Button Background="{x:Null}" BorderBrush="{x:Null}" Foreground="{x:Null}" Margin="0,50,0,0" HorizontalAlignment="Center" VerticalAlignment="Center" Grid.ColumnSpan="2" Grid.Row="1" Click="Button_Click" Style="{StaticResource ButtonStyle}"> 
             <Canvas x:Name="PLAY" HorizontalAlignment="Center" Height="102" UseLayoutRounding="False" VerticalAlignment="Center" Width="102"> 
              <Canvas x:Name="Layer_3" Height="96" Canvas.Left="2" Canvas.Top="2" Width="96" Margin="0" Background="{StaticResource TransparentBrush}"> 
               <Path Data="F1M0,0L29.333,16.936 0,33.871z" Fill="White" Height="33.871" Canvas.Left="38.26" Canvas.Top="30.998" Width="29.333" Stroke="#26000000"/> 
               <Ellipse Height="98" Stroke="#26000000" StrokeThickness="5" Width="98" HorizontalAlignment="Center" VerticalAlignment="Center"/> 
               <Ellipse Height="96" Stroke="White" StrokeThickness="3" Width="96" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="1" Canvas.Top="1"/> 
              </Canvas> 
             </Canvas> 
            </Button> 
           </Grid> 
          </DataTemplate> 
         </ListBox.ItemTemplate> 
        </ListBox> 
        <TextBlock x:Name="txt_NoConnection" Foreground="White" TextWrapping="Wrap" Text="{Binding LocalizedResources.NoConnection, Mode=OneWay, Source={StaticResource LocalizedStrings}}" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0,48,0,0" FontFamily="Segoe WP Light" Visibility="Collapsed"/> 
       </StackPanel> 
      </ScrollViewer> 
     </DataTemplate> 

和我說這是一個錯誤VS因爲我發現這一點:VS bug report

+0

我將ListBox ItemTemplate移出YOTWDataTemplate,並且錯誤消失... Windows Phone 8 Silverlight支持這一點。 Universal Apps似乎在這個實施方面落後了一步 – rickrvo