2010-09-02 5 views
2
public class RichTextBoxExtended : RichTextBox 
{ 
    static RichTextBoxExtended() 
    { 
     //DefaultStyleKeyProperty.OverrideMetadata(typeof(RichTextBoxExtended), new FrameworkPropertyMetadata(typeof(RichTextBoxExtended))); 
    } 

    public byte[] Text 
    { 
     get { return (byte[])GetValue(TextProperty); } 
     set { SetValue(TextProperty, value); } 
    } 

    // Using a DependencyProperty as the backing store for Text. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty TextProperty = 
     DependencyProperty.Register("Text", typeof(byte[]), typeof(RichTextBoxExtended), new UIPropertyMetadata(null, new PropertyChangedCallback(TextChangedCallback))); 

    private static void TextChangedCallback(DependencyObject obj, DependencyPropertyChangedEventArgs e) 
    { 
     RichTextBoxExtended richTextBoxExtended = obj as RichTextBoxExtended; 
     richTextBoxExtended.ChangeText(e); 
    } 

    private void ChangeText(DependencyPropertyChangedEventArgs e) 
    { 
     //clear out any formatting properties 
     TextRange range = new TextRange(base.Document.ContentStart, base.Document.ContentEnd); 
     range.ClearAllProperties(); 

     //load bytes into stream, load stream into range 
     MemoryStream stream = new MemoryStream(e.NewValue as byte[]); 
     range.Load(stream, DataFormats.Rtf); 
    } 
} 

Au-dessus est le contrôle personnalisé ...contrôle personnalisé WPF avec Unity ne pas résoudre

XAML mise en œuvre de contrôle personnalisé ...

<Grid> 
    <controls:RichTextBoxExtended x:Name="Document" Text="{Binding Path=File}"> 
    </controls:RichTextBoxExtended> 
</Grid> 

Associated VM ...

public class FileViewerViewModel : AViewModel 
{ 
    private byte[] _file = null; 

    public FileViewerViewModel(ILoggerFacade logger) 
    { 

    } 

    /// <summary> 
    /// Gets or sets the <seealso cref="DataFormats.Rtf"/> file representation as a <seealso cref="byte[]"/> 
    /// </summary> 
    public byte[] File 
    { 
     get 
     { 
      return _file; 
     } 
     set 
     { 
      _file = value; 
      RaiseChanged(() => this.File); 
     } 
    } 
} 

Enfin..si j'appelle ...

FileViewerView view = _container.Resolve<FileViewerView>(); 

Échec.

Resolution of the dependency failed, type = "cyos.infrastructure.Views.FileViewerView", name = "". Exception message is: The current build operation (build key Build Key[cyos.infrastructure.Views.FileViewerView, null]) failed: Object reference not set to an instance of an object. (Strategy type BuildPlanStrategy, index 3) 

Si je supprime la liaison à l'intérieur du XAML ...

<Grid> 
    <controls:RichTextBoxExtended x:Name="Document"> 
    </controls:RichTextBoxExtended> 
</Grid> 

Tout fonctionne sans accroc ... aucun problème ... idées?

EDIT:

changé à la création d'une nouvelle instance, sans passer par l'unité. Problème est toujours au même endroit, exception à la construction de FileViewerView à InitializeComponent() avec "Référence d'objet n'est pas définie sur une instance d'un objet."

à System.Windows.Markup.BamlRecordReader.ProvideValueFromMarkupExtension (MarkupExtension MarkupExtension, objet obj, membre de l'objet) à System.Windows.Markup.BamlRecordReader.ReadPropertyArrayEndRecord() à System.Windows.Markup.BamlRecordReader.ReadRecord (BamlRecord bamlRecord) à System.Windows.Markup.BamlRecordReader.Read (Boolean singleRecord) à System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment() à System.Windows.Markup.TreeBuilder.Parse() à System.Windows.Markup .XamlReader.LoadBaml (Flux de flux, ParserContext ParserContext, Object parent, Boolean closeStream) at System.Windows.Application.LoadComponent (Composant d'objet, Uri r esourceLocator) à l'adresse cyos.infrastructure.Views.FileViewerView.InitializeComponent() dans c: \ Documents and Settings \ amciver \ Mes documents \ dev \ cyos \ cyos \ cyos.infrastructure \ Views \ FileViewerView.xaml: ligne 1 à cyos. infrastructure.Views.FileViewerView..ctor (FileViewerViewModel viewModel) dans maintenant ...

Répondre

1

Je ne sais pas ce que le problème avec tableau, mais la liste <octet> fonctionne.

+0

Il a effectivement travaillé ... un peu frustré par cela ... la seule chose que je peux penser est que List = class byte = struct ... –

Questions connexes