C# on Windows Phone: The issue of MaxWidth and MaxHeight property being overlooked

As I organize my Canvases within a ListBox, I encounter an issue with the TextBlocks inside. Despite setting MaxWidth/Height or standard Height/Width properties on the TextBlock elements, these settings seem to be disregarded. This leads to text overflowing beyond the boundaries of the Canvas in certain situations.

I would greatly appreciate any guidance on this matter, and I hope that I am not simply missing something obvious!

Below is the code snippet (the first TextBlock being the one in question):

<ListBox Margin="0,-9,-12,0" ItemsSource="{Binding}" Name="listBoxNotes" HorizontalAlignment="Left" VerticalAlignment="Top" Width="400" Height="548">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel>
                <Canvas Height="175" Width="360" Background="{StaticResource PhoneAccentBrush}" toolkit:TiltEffect.IsTiltEnabled="True" Name="canvasNote" Tap="canvasNote_Tap">
                    <TextBlock Text="{Binding Title}" FontWeight="Bold" FontSize="26" Foreground="White" Canvas.Left="10" Canvas.Top="5" x:Name="Title" Width="100" MaxWidth="100"/>
                    <TextBlock Text="{Binding Details}" TextWrapping="Wrap" Width="352" FontSize="24" Foreground="White" Canvas.Left="10" Canvas.Top="35" />
                </Canvas>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Answer №1

One issue here is that Canvas does not restrict the size of its children, so the TextBlock control can expand as needed.

There are several possible solutions:

  • Avoid using TextBlock and use a TextBox instead
  • Consider using a different container like Border, Grid, or StackPanel instead of Canvas
  • Attempt to clip the content of the TextBlock

<TextBlock.Clip>
      <RectangleGeometry Rect="0, 0, 50, 30"/>
 </TextBlock.Clip>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Python Selenium: Having trouble navigating through two menus using ActionChains before selecting an element

I've encountered an issue where I am attempting to click on an element that is located two levels down in a menu that only appears when hovering over it. For example: Menu -> Sub-Menu -> Element to be clicked content_menu = driver.find_element ...

utilizing symbols from a vector graphic icon库

There are countless icon images to be found on the internet. Recently, I came across this particular set and now I'm stumped on how to actually utilize them. Despite my efforts to find tutorials online, I have come up short in finding any helpful reso ...

How can a JQuery function be used with SVG to trigger a second animation immediately after the first animation is finished?

For the handwriting effect animation, I utilized the animation-delay technique by dividing the object wherever it intersected, drawing paths, and converting them into clipping masks. This involved breaking the letter "W" into four parts, creating different ...

Resetting CSS animations in Vue is a simple process that can be achieved

Here is a sample list: var v = new Vue({ 'el' : '#app', 'data' : { 'list' : [1,2,3,4,5,6,7,8,9,10] }, methods: { activateClass($event){ $event.target.classList.remove('animate'); ...

Is there a way to apply -webkit-line-clamp to this JavaScript content using CSS?

i have a random-posts script for my blogger website <div class="noop-random-posts"><script type="text/javascript"> var randarray = new Array(); var l=0; var flag; var numofpost=10; function nooprandomposts(json){ var total = ...

Chosen link fails to update color

I've successfully implemented a navigation bar that changes the content in the body when each link is selected. Utilizing AJAX for dynamic content changing, I can change the color of menu items on hover but am facing issues with changing the color upo ...

Serializing and deserializing established data types in a manner reminiscent of Microsoft

For a while now, I have been using Microsoft's DataContractJsonSerializer to serialize and deserialize my business objects into data transfer objects (DTO) formatted as JSON. The DTOs are labeled with the DataContract attribute. Here's a small ex ...

Is it possible for me to make a class in my namespace by exposing a class from a different .NET namespace?

Is it possible for me to expose a class from another .net namespace as a class within my own namespace? For example, I am using the class antlr.collections.AST as the return type in one of my functions. Currently, users need to have using antlr.collection ...

Maintaining Changes in Javascript and CSS

I have created a header that can slide in and out of view with a toggle function. However, I want the header to be in the down position by default, without requiring users to click the toggle every time a new page loads. I have limited knowledge of JavaScr ...

Guide on dynamically changing the color of polymer 1.0 paper-button from an array of colors

I have an array called buttonColors that contains a set of colors in hex format. I am looking to create paper-buttons, each with the color from the buttonColors array. How can I achieve this in Polymer 1.0? <template is="dom-repeat" items="{{buttonCo ...

Challenges with Setting Up Selenium Grid Hub and Nodes

Urgent Help Needed! I have successfully set up a Selenium grid with the following configuration: -Machine A with a hub and node (node on the same machine as the hub) -Machine B (different from the hub), with 2 nodes Now, I have a hub and 3 nodes - 1 on ...

Please rewrite your request so I can better assist you

I've recently been working on localizing resources in a custom assembly for my ASP page, which generates images with text in different languages. Everything was running smoothly after deploying the application in IIS. However, after a few hours, an er ...

Issue encountered while serializing ASP.NET objects (table)

I'm looking for a way to save an entire ASP table to SQL as an object, without having to save each element individually and then reconstruct the table later. My idea is to serialize the object, store it in SQL as a string, and then deserialize it when ...

How can I customize the color of the check mark symbol in a bootstrap checkbox?

Here is my customized HTML code using Bootstrap: <div class="col-lg-4 col-12 text-center"> <div style="width: 80%; margin: auto"> <ul class="list-group"> {% for sl in my_list %} <li ...

Inquire about the ExpectedConditions

public static IWebElement RetrieveElement(IWebDriver driver, By by, int waitForSeconds, bool verifyVisibility = false) { WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds((double)waitForSeconds)); IWebElement element; ...

Unfortunately, Rem fails to honor the preferences of users on their smartphones

Trying to incorporate rem units to respect user-defined font-size: Initially, I included the following line in my CSS file: html { font-size: 62.5%; } Subsequently, I applied font-size using rem units to my element. For example: .header{ font-size: 1.5 ...

Is there a way to invoke asynchronous methods in ASP.NET using C# version 4.0?

In my research, I have learned about the await and async keywords introduced in .NET 4.5 which make calling async methods easier. Currently, I am exploring how to perform async calls in C# 4.0. An example I am interested in is making an async call while da ...

HTML file unable to connect with CSS stylesheet

I'm facing an issue where my CSS stylesheet and HTML files aren't linking properly. Here is the code snippet from my HTML file: <head> <title>Website Sample</title> <meta charset="UTF-8"> <meta http-equiv= ...

Preventing the user from using the mouse wheel until the CSS animation finishes

I am working with multiple functions that are triggered by scrolling the mouse wheel up and down. These functions must be called in a specific order, but the issue arises when users scroll quickly causing the CSS animations from the previous function to ...

The effects of external CSS are not being displayed or are being overridden

I am currently working on a webpage design that resembles the style of Microsoft's website. I came across a tutorial on W3 Schools for creating an image slideshow, which can be found here: https://www.w3schools.com/howto/howto_js_slideshow.asp. The ex ...