2017-06-12 5 views
-1

ich im Anschluss an der Head First C# 3. Auflage, im ersten Kapitel zu ändern, fragt es mich Text von Textblock zu ändern, aber wenn ich versuche, bekomme ich folgende Fehlermeldung:Erste Fehler, wenn ich versuche TextBlock- Text

InvalidCastException: Unable to cast object of type 'Windows.UI.Text.TextDecorations' to type'System.Windows.TextDecorationCollection'.

enter image description here

Das Buch schlägt vor, ich Visual Studio Express 2012 für Windows 8 verwenden, und ich verfolge die Vorschläge.

XAML-Code:

<common:LayoutAwarePage 
    x:Name="pageRoot" 
    x:Class="Save_The_Humans.MainPage" 
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="using:Save_The_Humans" 
    xmlns:common="using:Save_The_Humans.Common" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d"> 

    <Page.Resources> 

     <!-- TODO: Delete this line if the key AppName is declared in App.xaml --> 
     <x:String x:Key="AppName">Save The Humans</x:String> 
    </Page.Resources> 

    <!-- 
     This grid acts as a root panel for the page that defines two rows: 
     * Row 0 contains the back button and page title 
     * Row 1 contains the rest of the page layout 
    --> 
    <Grid Style="{StaticResource LayoutRootStyle}"> 
     <Grid.ColumnDefinitions> 
      <ColumnDefinition Width="160"/> 
      <ColumnDefinition/> 
      <ColumnDefinition Width="160"/> 
     </Grid.ColumnDefinitions> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="140"/> 
      <RowDefinition/> 
      <RowDefinition Height="160"/> 
     </Grid.RowDefinitions> 

     <!-- Back button and page title --> 
     <Grid Grid.ColumnSpan="3"> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto"/> 
       <ColumnDefinition Width="*"/> 
      </Grid.ColumnDefinitions> 
      <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}"/> 
      <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}"/> 
     </Grid> 
     <Button x:Name="startButton" Content="Start!" HorizontalAlignment="Center" Grid.Row="2" VerticalAlignment="Center" 
       RenderTransformOrigin="0.562,0.526"/> 
     <ProgressBar Grid.Column="1" HorizontalAlignment="Left" Height="10" Margin="475,37,0,0" Grid.Row="2" VerticalAlignment="Top" Width="100"/> 
     <StackPanel Grid.Column="2" Margin="33,37,50,85" Orientation="Vertical" Grid.Row="2"> 
      <ContentControl Content="ContentControl" HorizontalAlignment="Left" VerticalAlignment="Top"/> 
     </StackPanel> 
     <Canvas Grid.Column="1" HorizontalAlignment="Left" Height="100" 
       Margin="475,175,0,0" Grid.Row="1" VerticalAlignment="Top" Width="100"/> 

     <TextBlock Grid.Column="2" HorizontalAlignment="Left" Margin="24,2,0,0" Grid.Row="2" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Style="{StaticResource SubheaderTextStyle}"/> 

     <VisualStateManager.VisualStateGroups> 

      <!-- Visual states reflect the application's view state --> 
      <VisualStateGroup x:Name="ApplicationViewStates"> 
       <VisualState x:Name="FullScreenLandscape"/> 
       <VisualState x:Name="Filled"/> 

       <!-- The entire page respects the narrower 100-pixel margin convention for portrait --> 
       <VisualState x:Name="FullScreenPortrait"> 
        <Storyboard> 
         <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style"> 
          <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}"/> 
         </ObjectAnimationUsingKeyFrames> 
        </Storyboard> 
       </VisualState> 

       <!-- The back button and title have different styles when snapped --> 
       <VisualState x:Name="Snapped"> 
        <Storyboard> 
         <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style"> 
          <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}"/> 
         </ObjectAnimationUsingKeyFrames> 
         <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style"> 
          <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}"/> 
         </ObjectAnimationUsingKeyFrames> 
        </Storyboard> 
       </VisualState> 
      </VisualStateGroup> 
     </VisualStateManager.VisualStateGroups> 
    </Grid> 
</common:LayoutAwarePage> 

Source Code

using System; 
using System.Collections.Generic; 
using System.IO; 
using System.Linq; 
using Windows.Foundation; 
using Windows.Foundation.Collections; 
using Windows.UI.Xaml; 
using Windows.UI.Xaml.Controls; 
using Windows.UI.Xaml.Controls.Primitives; 
using Windows.UI.Xaml.Data; 
using Windows.UI.Xaml.Input; 
using Windows.UI.Xaml.Media; 
using Windows.UI.Xaml.Navigation; 

// The Basic Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234237 

namespace Save_The_Humans 
{ 
    /// <summary> 
    /// A basic page that provides characteristics common to most applications. 
    /// </summary> 
    public sealed partial class MainPage : Save_The_Humans.Common.LayoutAwarePage 
    { 
     public MainPage() 
     { 
      this.InitializeComponent(); 
     } 

     /// <summary> 
     /// Populates the page with content passed during navigation. Any saved state is also 
     /// provided when recreating a page from a prior session. 
     /// </summary> 
     /// <param name="navigationParameter">The parameter value passed to 
     /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested. 
     /// </param> 
     /// <param name="pageState">A dictionary of state preserved by this page during an earlier 
     /// session. This will be null the first time a page is visited.</param> 
     protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState) 
     { 
     } 

     /// <summary> 
     /// Preserves state associated with this page in case the application is suspended or the 
     /// page is discarded from the navigation cache. Values must conform to the serialization 
     /// requirements of <see cref="SuspensionManager.SessionState"/>. 
     /// </summary> 
     /// <param name="pageState">An empty dictionary to be populated with serializable state.</param> 
     protected override void SaveState(Dictionary<String, Object> pageState) 
     { 
     } 
    } 
} 

Fehlertext:

InvalidCastException: Unable to cast object of type 'Windows.UI.Text.TextDecorations' to type 'System.Windows.TextDecorationCollection'. 

Stack Trace

at Microsoft.Expression.DesignSurface.Tools.Text.TextBlockEditProxy.Instantiate() 
    at Microsoft.Expression.DesignSurface.Tools.Text.TextEditProxy.AddToScene(Boolean visible) 
    at Microsoft.Expression.DesignSurface.Tools.Text.TextToolBehavior.AddEditProxyToScene(TextEditProxy textEditProxy, Boolean visible) 
    at Microsoft.Expression.DesignSurface.Tools.Text.TextToolBehavior.FindOrCreateEditProxy(SceneNode textElement, Boolean active) 
    at Microsoft.Expression.DesignSurface.Tools.Text.TextToolBehavior.BeginTextEdit(SceneNode textElement) 
    at Microsoft.Expression.DesignSurface.Tools.Text.TextToolBehavior.EditDifferentElement(SceneNode element, Boolean returnFocus) 
    at Microsoft.Expression.DesignSurface.Tools.Text.TextToolBehavior.OnAttach() 
    at Microsoft.Expression.DesignSurface.Tools.EventRouter.PushBehavior(ToolBehavior newActiveBehavior) 
    at Microsoft.Expression.DesignSurface.View.SceneView.TryEnterTextEditMode(Boolean textElementOnly) 
    at Microsoft.Expression.DesignSurface.SceneCommands.EditTextCommand.Execute() 
    at Microsoft.Expression.Utility.Commands.CommandTarget.ExecuteCommand(String commandName, CommandInvocationSource invocationSource) 
    at Microsoft.Expression.Utility.UserInterface.CommandBarButtonBase.<>c__DisplayClass1.<Execute>b__0() 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
    at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler) 

InnerException: None 

Warum habe ich zwei minus ?!

+0

Können Sie Ihren Code zeigen? –

+0

https://stackoverflow.com/questions/30937620/customrichtextbox-strikethrough-textdecoration – fluffy

+0

Bitte fügen Sie den Text des Fehlers in die Frage ein. –

Antwort

0

Ich löste das Problem aus Versehen, nachdem ich einen Fehler bekam, änderte ich den Textwert im XAML-Code und löste das Problem, aber ich erhalte immer noch einen Fehler, wenn ich auf Text bearbeiten klicke.

image shows problem

image shows after solution

Verwandte Themen