Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

How to add events back, after load by XamlReader

$
0
0

I created a class Rtb which is to create a new RichTextBox, below is the constructor and list

publicRtb(){
        newRTB =newRichTextBox();
        newRTB.IsReadOnly=true;
        newRTB.MouseDoubleClick+=newMouseButtonEventHandler(newRTB_MouseDoubleClick);
        reqName ="Box"+NextID.ToString();
        newRTB.Name= reqName;}List<Rtb> rtbeditor =newList<Rtb>();

I want to click the menu, add a BlockUIContainer, and a new richtextbox inside the blockuicontainer, see below

privatevoid menuReq_Click(object sender,RoutedEventArgs e){BlockUIContainer newBlockUC =newBlockUIContainer();
        newBlockUC.Margin=newThickness(50,10,50,10);Bigwin.Document.Blocks.Add(newBlockUC);//Bigwin is a big richtextbox
        rtbeditor.Add(newRtb());Rtb newRichTB =newRtb();
        newBlockUC.Child= newRichTB.newRTB;}

Then I save it by using XamlWriter, the problem is XamlWriter can not save event, so i have to add the event back when loading it, see below

privatevoidLoadRtfFile(string path){FileStream fs =newFileStream(path,FileMode.Open);FlowDocument doc =XamlReader.Load(fs)asFlowDocument;Bigwin.Document= doc;
        fs.Close();foreach(var rtb in rtbeditor)
            rtb.MouseDoubleClick+= req1_MouseDoubleClick;//add event to every richtextbox}

But the doubleclick event is not added by this solution, I think the last part of codes has problem. So how to add events to every created richtextbox?


Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>