locked
Changing content of one label, based on the content of another RRS feed

  • Question

  • Hello all,

    I need some advice on how to go about doing something that should be simple.

    Basically, I have two labels, that will be used in a marquee animation. When label one gets changed, I want label two to mimic label one's content. Since there is no ContentChanged Event for labels, I have been relying on the SizeChanged event of label one to do the job.

    However, the issue arises when label one's content extends past that of its parent container, thus no longer firing SizeChanged.

    When label one's supposed length is equal to or greater than that of its container, is when I would start the marquee animation.

    Basically, I need a sure fire, reliable, 100% accurate way to update label two's content to match that of label one's despite its length.

    I have read the following: Label.Content Changed Event

    However this does not solve the issue, as the event fires for "all" custom label classes, due to the ContentProperty being declared Static/Shared.

    Thanks in advance!

    Tuesday, December 30, 2014 6:39 AM

Answers

  • try LayoutUpdated event, it worked fine for me.
    • Marked as answer by Blazing Ardor Tuesday, December 30, 2014 8:02 AM
    Tuesday, December 30, 2014 7:55 AM

All replies

  • try TextInput or SizeChanged events.
    Tuesday, December 30, 2014 6:51 AM
  • Hi. You could bind the second label's content to the first label's content. For example:

    <Label x:Name="lbl1"></Label>
    <Label x:Name="lbl2" Content="{Binding ElementName=lbl1,Path=Content}"></Label>


    • Edited by JayChase Tuesday, December 30, 2014 6:54 AM
    Tuesday, December 30, 2014 6:54 AM
  • Unfortunately, TextInput does not fire when I change the label's Content in code, and SizeChanged has limitations.
    Tuesday, December 30, 2014 7:03 AM
  • I tried the above, however when the label one gets cut off by it's container, it no longer updates label two. I have confirmed in code that label one's content continues to be updated, where as label two's content no longer gets updated.
    Tuesday, December 30, 2014 7:09 AM
  • Can you post an example of your XAML? A label being cut off by it's container wouldn't cause the binding to stop updating. There must be something else happening.
    Tuesday, December 30, 2014 7:21 AM
  • <UserControl x:Class="CustomControls.UserControls.ValidationUserControl"
                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                 mc:Ignorable="d" Height="36" Width="120">
        <Grid x:Name="z">
            <TextBox x:Name="txtBase" Text="TextBox" Margin="0,0,0,13"/>
            <Label x:Name="lblStatus" Content="Status" HorizontalAlignment="Left" Margin="5,0,0,0" VerticalAlignment="Bottom" FontSize="10" Foreground="#FFE12828" FontWeight="Bold">
                <Label.Effect>
                    <DropShadowEffect BlurRadius="5" ShadowDepth="1"/>
                </Label.Effect>
            </Label>
            <Label x:FieldModifier="Friend" x:Name="lblMarquee" Content="{Binding ElementName=lblStatus, Path=Content}" HorizontalAlignment="Right" Margin="0,23,-29,0" FontSize="10" Foreground="#FFE12828" FontWeight="Bold" Background="Transparent" Height="13" VerticalAlignment="Top">
                <Label.Effect>
                    <DropShadowEffect BlurRadius="5" ShadowDepth="1"/>
                </Label.Effect>
            </Label>
        </Grid>
    </UserControl>
    

    Tuesday, December 30, 2014 7:30 AM
  • If it matters, I am using this as a User Control on another page.
    Tuesday, December 30, 2014 7:30 AM
  • try LayoutUpdated event, it worked fine for me.
    • Marked as answer by Blazing Ardor Tuesday, December 30, 2014 8:02 AM
    Tuesday, December 30, 2014 7:55 AM
  • Thanks! This solved the problem.
    Tuesday, December 30, 2014 8:02 AM