dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2018
    Posts
    4

    Question How to use XAML to share some of the properties of multiple TextBlocks

    Is there a standard way in XAML to collect similarly derived properties with the same values from several controls into one place? What is the best way to do it? The code below demonstrates the functionality I am thinking of with WPF TextBlocks, although it doesn't do what I want. It ignores the Canvas.Left and Canvas.Top property values and concatenates each successive fragment of text (starting at Left,Top=0,0). Canvas.Left,Top are what the designer used in <TextBlocks>—lines which I duplicated and reformatted into the below. I didn't see any x, y properties in class TextBlock itself. (Perhaps I simply should be using something other than Canvas.Left, Top for the TextBlocks' x,y?)

    DrawingWindow is defined as (C#): public class DrawingWindow : Canvas { }
    to which I intend to add additional drawing methods.
    Code:
    <local:DrawingWindow x:Class="MyApp.WelcomeScreen"
        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" 
        xmlns:local="clr-namespace:MyApp"
        mc:Ignorable="d" 
        d:DesignHeight="500" d:DesignWidth="500"
        Background="Black"
        Margin="1,1,1,1">
        <TextBlock Foreground="Orange" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="350" FontFamily="FreeSans" FontSize="14">
            <TextBlock Canvas.Left="100" Canvas.Top="100" Text="Now is the time\nfor all good men"/>
            <TextBlock Canvas.Left="120" Canvas.Top="150" Text="to come to"/>
            <TextBlock Canvas.Left="140" Canvas.Top="200" Text="the aid of their country."/>
        </TextBlock>
    </local:DrawingWindow>

  2. #2
    Join Date
    Jan 2018
    Posts
    4

    Re: How to use XAML to share some of the properties of multiple TextBlocks

    I have moved this question elsewhere. (At the moment it is here.)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.