How wide is my TextBlock after creating it?How do I enumerate an enum in C#?How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?How to make div not larger than its contents?How to underline a TextBlock on a MouseEnterHow can I have a ListBox auto-scroll when a new item is added?Set the sum of listboxitems to a textblockHow to show particular textblock on button click in WPF?Fit WPF listbox items size to fit windowWPF - Change the color of an entire textblock lineListbox focus reset after selecting any item

Can a creature sustain itself by eating its own severed body parts?

Host telling me to cancel my booking in exchange for a discount?

What's the physical meaning of the statement that "photons don't have positions"?

Find position equal columns of matrix

Why does Plot only sometimes use different colors for each curve

What does Windows' "Tuning up Application Start" do?

What is the difference between uniform velocity and constant velocity?

What is the minimum wait before I may I re-enter the USA after a 90 day visit on the Visa B-2 Program?

Are there foods that astronauts are explicitly never allowed to eat?

Making an example from 'Clean Code' more functional

Grease/lubricate rubber stabilizer bar bushings?

ISCSI, multiple initiaros for the same lun

Manager is asking me to eat breakfast from now on

Killing a star safely

Install suspension forks on non-suspension bike

Why can't a country print its own money to spend it only abroad?

Do we have to introduce the character's name before using their names in a dialogue tag?

Ethiopian Airlines tickets seem to always have the same price regardless of the proximity of the date?

Do pedestrians imitate automotive traffic?

Can two waves interfere head on?

Why are flying carpets banned while flying brooms are not?

Does the Bracer of Flying Daggers really let a thief make 4 attacks per round?

What would be the effects of (relatively) widespread precognition on the stock market?

Why would word of Princess Leia's capture generate sympathy for the Rebellion in the Senate?



How wide is my TextBlock after creating it?


How do I enumerate an enum in C#?How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?How to make div not larger than its contents?How to underline a TextBlock on a MouseEnterHow can I have a ListBox auto-scroll when a new item is added?Set the sum of listboxitems to a textblockHow to show particular textblock on button click in WPF?Fit WPF listbox items size to fit windowWPF - Change the color of an entire textblock lineListbox focus reset after selecting any item






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I use a ListBox in a C#, WPF project. It works. Then I Tried to give the ListBox Items a individual Background. I failed. Now I make a TextBlock first, give them a individual Background and then I put it into the ListBox. It works fine but my problem is that every single line in the Listbox have their own width. I would like have that every ListBox Item has the same largest width. I tried to ask for the width when i created the TextBlock but at this time the width=NaN and the actualWidth=0.



I tried to read all ListBox Items widths with a Button Click Event and it worked.



What do i have to do so that I can do it in the same function as I filled the ListBox?



I would like that every Listbox has the same largest width.
At this Point each ListBox Item has its own width depending on the text.










share|improve this question



















  • 1





    There are better ways of colouring items in a ListBox than setting the Background of TextBlocks. What did you try?

    – mm8
    Mar 26 at 13:22












  • As @mm8 said, there are better ways than the one you are currently trying. What are you actually trying? Are you trying to give each item a unique background color or are you trying to change the color when something in particular happens?

    – IDarkCoder
    Mar 26 at 14:58











  • Tell me one way to color a ListBox.Item individuell? I did nott find a working way!

    – gFort
    Mar 27 at 7:05

















0















I use a ListBox in a C#, WPF project. It works. Then I Tried to give the ListBox Items a individual Background. I failed. Now I make a TextBlock first, give them a individual Background and then I put it into the ListBox. It works fine but my problem is that every single line in the Listbox have their own width. I would like have that every ListBox Item has the same largest width. I tried to ask for the width when i created the TextBlock but at this time the width=NaN and the actualWidth=0.



I tried to read all ListBox Items widths with a Button Click Event and it worked.



What do i have to do so that I can do it in the same function as I filled the ListBox?



I would like that every Listbox has the same largest width.
At this Point each ListBox Item has its own width depending on the text.










share|improve this question



















  • 1





    There are better ways of colouring items in a ListBox than setting the Background of TextBlocks. What did you try?

    – mm8
    Mar 26 at 13:22












  • As @mm8 said, there are better ways than the one you are currently trying. What are you actually trying? Are you trying to give each item a unique background color or are you trying to change the color when something in particular happens?

    – IDarkCoder
    Mar 26 at 14:58











  • Tell me one way to color a ListBox.Item individuell? I did nott find a working way!

    – gFort
    Mar 27 at 7:05













0












0








0








I use a ListBox in a C#, WPF project. It works. Then I Tried to give the ListBox Items a individual Background. I failed. Now I make a TextBlock first, give them a individual Background and then I put it into the ListBox. It works fine but my problem is that every single line in the Listbox have their own width. I would like have that every ListBox Item has the same largest width. I tried to ask for the width when i created the TextBlock but at this time the width=NaN and the actualWidth=0.



I tried to read all ListBox Items widths with a Button Click Event and it worked.



What do i have to do so that I can do it in the same function as I filled the ListBox?



I would like that every Listbox has the same largest width.
At this Point each ListBox Item has its own width depending on the text.










share|improve this question
















I use a ListBox in a C#, WPF project. It works. Then I Tried to give the ListBox Items a individual Background. I failed. Now I make a TextBlock first, give them a individual Background and then I put it into the ListBox. It works fine but my problem is that every single line in the Listbox have their own width. I would like have that every ListBox Item has the same largest width. I tried to ask for the width when i created the TextBlock but at this time the width=NaN and the actualWidth=0.



I tried to read all ListBox Items widths with a Button Click Event and it worked.



What do i have to do so that I can do it in the same function as I filled the ListBox?



I would like that every Listbox has the same largest width.
At this Point each ListBox Item has its own width depending on the text.







c# wpf listbox width






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 15:00









Sam Xia

268 bronze badges




268 bronze badges










asked Mar 26 at 12:35









gFortgFort

11 bronze badge




11 bronze badge







  • 1





    There are better ways of colouring items in a ListBox than setting the Background of TextBlocks. What did you try?

    – mm8
    Mar 26 at 13:22












  • As @mm8 said, there are better ways than the one you are currently trying. What are you actually trying? Are you trying to give each item a unique background color or are you trying to change the color when something in particular happens?

    – IDarkCoder
    Mar 26 at 14:58











  • Tell me one way to color a ListBox.Item individuell? I did nott find a working way!

    – gFort
    Mar 27 at 7:05












  • 1





    There are better ways of colouring items in a ListBox than setting the Background of TextBlocks. What did you try?

    – mm8
    Mar 26 at 13:22












  • As @mm8 said, there are better ways than the one you are currently trying. What are you actually trying? Are you trying to give each item a unique background color or are you trying to change the color when something in particular happens?

    – IDarkCoder
    Mar 26 at 14:58











  • Tell me one way to color a ListBox.Item individuell? I did nott find a working way!

    – gFort
    Mar 27 at 7:05







1




1





There are better ways of colouring items in a ListBox than setting the Background of TextBlocks. What did you try?

– mm8
Mar 26 at 13:22






There are better ways of colouring items in a ListBox than setting the Background of TextBlocks. What did you try?

– mm8
Mar 26 at 13:22














As @mm8 said, there are better ways than the one you are currently trying. What are you actually trying? Are you trying to give each item a unique background color or are you trying to change the color when something in particular happens?

– IDarkCoder
Mar 26 at 14:58





As @mm8 said, there are better ways than the one you are currently trying. What are you actually trying? Are you trying to give each item a unique background color or are you trying to change the color when something in particular happens?

– IDarkCoder
Mar 26 at 14:58













Tell me one way to color a ListBox.Item individuell? I did nott find a working way!

– gFort
Mar 27 at 7:05





Tell me one way to color a ListBox.Item individuell? I did nott find a working way!

– gFort
Mar 27 at 7:05












0






active

oldest

votes










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357342%2fhow-wide-is-my-textblock-after-creating-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes




Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.







Is this question similar to what you get asked at work? Learn more about asking and sharing private information with your coworkers using Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55357342%2fhow-wide-is-my-textblock-after-creating-it%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript