Thursday 15 July 2010

c# - Find named elements in WinRT XAML page -


I am trying to add notes that are represented by symbols in a RichTextBlock and then they are all tapped. Add event handler I found out that I can not add handlers before programmatically inserting into the page in XAM, so I have to meet each element with a certain naming method and a handler for each Will Hna.

This is my code:

  Private zero assignNoteHandlers () {// for each note expected on screen (int i = 0; I & lt; currentTextFile .noteCount; i ++) {try {string noteName = string. Format ("note {0}", i); Image note icon = (image) PageRoot.Findname (notnam); Note Icon.Tapped + = Note Icon_Tapped; } Hold {Debug.WriteLine ("Image Note {0} not found", i); to continue; }}}   

When I look at the screen, I can put the note icon in the text as it should be.

The text HTML file on the screen, in which I include this string for the program for each note:

  string notes XML = string.Format ("& lt; Note Name = \ "Note {0} \" src = \ "Property / TEMPNoteIcon.png \" / & gt; ", i);   

This psuedo-HTML converts to XAM with this XSLT template:

   & Lt; / XSL: Specialty & gt; & Lt ;! - Disabled & lt; Xsl: attribute name = "name" & gt; & Lt; Xsl: Select the value = "@ name" /> & Lt; / XSL: Specialty & gt; - & gt; & Lt; Xsl: attribute name = "source" & gt; & Lt; Xsl: Select Value = "@ Source" /> & Lt; / XSL: Specialty & gt; & Lt; Xsl: applied-template / & gt; & Lt; / Image & gt; & Lt; / InlineUIContainer & gt; & Lt; / Span & gt; & Lt; / XSL: Templates & gt;   

I have tried to use both "name" and "x: name" (but I can not do both together).

So, my problem is that in the first section of code (which runs the last), the image note icon is always zero.

I know this is a very complex question, but can someone help me understand this?

Edit: Here is the code that fills RichTextBlock (I download from the Web),

  Private static async zero HtmlChanged (DependencyObject d, DependencyPropertyChangedEventArgs e) {// Received Goal RichTextBlock RichTextBlock richText as rich text block = D; If return (Rich Text == blank); (String, e.NewValue "
{0} ") // wrap the value of the HTML property in a div and convert it to a new RichTextBlock string XHTML = String.Format; RichTextBlock newRichText = Faucet; If (Windows.ApplicationModel.DesignMode.DesignModeEnabled) {// In Design mode we swallow all the exceptions to make xaml = "more favorable string; Try {xaml = wait> convert HTML toxymRIT ITT block (XHTML); NewRichText = (Rich Text Block) XamlReader.Load (xaml); } Hold (exception before) {string errorxaml = String.Format (@ "from & lt; RichTextBlock xmlns = 'http: //schemas.microsoft.com/winfx/2006/xaml/presentation' xmlns: x = 'http: / / Schema .microsoft.com / winfx / 2006 / XAML '& gt; & lt; paragraphs; while an HTML change to XAML an exception occurred: & lt; / para & gt; {0} & lt; / Paragraph & gt; & lt; paragraph & gt; & lt; paragraph & gt; HTML; & lt; paragraphs & gt; {1} & lt; / paragraph & gt; & lt; paragraph & gt; & lt; paragraph & Gt; XAML: & lt; / paragraph & gt; & lt; paragraphs & gt; {2} & lt; / para & gt; & lt; / RichTextBlock & gt; ", pre-message, encoded XML (XHTML) , Nos Ksail (xaml)); NewRichText = (Rich TextBox) XamlReader.Load (errorxaml); } // Display a friendly error in design mode. } Else {// is not in design mode, we allow the app to handle any exception string xaml = await ConvertHtmlToXamlRichTextBlock (xhtml); NewRichText = (Rich Text Block) XamlReader.Load (xaml); } // Clear Rich Textback Rich Text Text to Block in New RichTextBlock. Bocks.Clear (); If (newRichText! = Null) {for (int i = newRichText.Blocks.Count - 1; i> = 0; i--) {block b = newRichText.Blocks [i]; NewRichText.Blocks.RemoveAt (i); Richtext.Blocks.Insert (0, b); }}}}

You do not need to create your RichTextBlock through XAML It can do this:

  var rtb = new rich text block (); Var paragraph = new paragraph (); Paragraph.inline. Add (new run {text = "hello"}); Paragraph.inline. Add (New Inline UI Container {Child = New Button} {Content = "World"}}); Rtb.Blocks.Add (paragraph); (Grid) this.Content .Children.Add (RTB);    

No comments:

Post a Comment