Marcus
Marcus

Reputation: 116

How To Add Properties To New Object That You're Instantiating?

var par = new Paragraph(new Run(""));
par.BorderBrush = Brushes.Black;
ThicknessConverter converter = new ThicknessConverter();
par.BorderThickness = (Thickness)converter.ConvertFromString("0.02cm");

I'm trying to later change "par" to have different text in it, but I don't know how to do it without resetting the properties:

par = new Paragraph(new Run("new text"));

Is there either a way to combine the lines setting the border brush and thickness with the instantiation of par, or just to change the text in the run?

Upvotes: 1

Views: 130

Answers (3)

Josh Heaps
Josh Heaps

Reputation: 296

What you would want to do is create, and assign a variable, as the Run(); object. Run has a text property that you can change.

var run = new Run("");
var par = new Paragraph(new Run(""));
par.BorderBrush = Brushes.Black;
ThicknessConverter converter = new ThicknessConverter();
par.BorderThickness = (Thickness)converter.ConvertFromString("0.02cm");
run.Text = string.Empty; //Your code here

Changing the Run object should change what the variable par has.

Upvotes: 2

Marcus
Marcus

Reputation: 116

I think it's something like

var par = new Paragraph(new Run("")){BorderBrush= Brushes.Black, etc.};

Upvotes: 1

Harrison Cooper
Harrison Cooper

Reputation: 23

Since it will be working on references why don't you just create a string:

string text = "";

use that instead and then you can change it programmatically or through a text box or something.

Upvotes: 0

Related Questions