Note that there are some explanatory texts on larger screens.

plurals
  1. POInheriting values declared at UserControl instantiation
    primarykey
    data
    text
    <p>First off, I apologize if this question has been asked before. I've done a bit of Google searching but I'm not really sure what the correct keywords are to find what I'm looking for.</p> <p>Basically my problem is simple to understand. I have a Silverlight project and on the MainPage.xaml I have declared a UserControl and given it a height and a width.</p> <pre><code>&lt;Grid&gt; &lt;control:AlarmButton Height="50" Width="50" /&gt; &lt;/Grid&gt; </code></pre> <p>Now within AlarmButton I have a button that has its own Control Template which is set up the way I want. It has a content presenter within it right now.</p> <pre><code>&lt;UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" x:Class="Alarms.AlarmButton"&gt; &lt;UserControl.Resources&gt; &lt;ControlTemplate x:Key="StatusButton" &gt; &lt;Viewbox Stretch="Fill"&gt; &lt;Grid&gt; &lt;Path x:Name="Base" StrokeThickness="1.0" Stroke="#ff000000" StrokeMiterLimit="1.0" Fill="#ff666666" Data="F1 M 99.500,99.500 L 0.500,99.500 L 0.500,0.500 L 99.500,0.500 L 99.500,99.500 Z"/&gt; &lt;Path x:Name="Interior" Opacity="0.5" StrokeThickness="1.0" Stroke="#ff191919" StrokeMiterLimit="1.0" Data="F1 M 97.500,97.500 L 2.500,97.500 L 2.500,2.500 L 97.500,2.500 L 97.500,97.500 Z"&gt; &lt;Path.Fill&gt; &lt;LinearGradientBrush MappingMode="Absolute" StartPoint="2.500,2.499" EndPoint="97.500,97.499"&gt; &lt;LinearGradientBrush.GradientStops&gt; &lt;GradientStop Offset="0.00" Color="#3FFFFFFF"/&gt; &lt;GradientStop Offset="0.151" Color="Transparent"/&gt; &lt;GradientStop Offset="1.00" Color="#BFFFFFFF"/&gt; &lt;GradientStop Color="#53FFFFFF" Offset="0.655"/&gt; &lt;/LinearGradientBrush.GradientStops&gt; &lt;LinearGradientBrush.Transform&gt; &lt;MatrixTransform Matrix="1.000,0.000,-0.000,-1.000,0.000,100.000" /&gt; &lt;/LinearGradientBrush.Transform&gt; &lt;/LinearGradientBrush&gt; &lt;/Path.Fill&gt; &lt;/Path&gt; &lt;Path x:Name="LargeShader" Opacity="0.1" Fill="#ffffffff" Data="F1 M 94.667,18.667 L 94.667,94.667 L 6.333,94.667 C 6.333,94.667 94.667,67.348 94.667,18.667 Z"/&gt; &lt;Path x:Name="SmallShader" Opacity="0.1" Fill="#ffffffff" Data="F1 M 94.667,43.667 L 94.667,94.667 L 20.333,94.667 C 20.333,94.667 94.667,76.334 94.667,43.667 Z"/&gt; &lt;ContentPresenter x:Name="contentPresenter" Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/&gt; &lt;/Grid&gt; &lt;/Viewbox&gt; &lt;/ControlTemplate&gt; &lt;/UserControl.Resources&gt; &lt;Grid &gt; &lt;Button Template="{StaticResource StatusButton}" &gt; &lt;TextBlock Text="this is a text box" TextTrimming="WordEllipsis" /&gt; &lt;/Button&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>Later on I'm going to bind the Text property to a DependencyProperty so I can use this button with multiple text. What I want to happen is if the text is too big it will ellipse it and not have the box change or the textblock overflow. I just need to bind the height and width of the TextBlock to some values to contain it.</p> <p>My question is this; is it possible for the TextBlock to bind its height and width to the values as declared in the MainPage.xaml? Or is this more complicated than I imagine? Is there a better way to go about this?</p> <p><strong>EDIT</strong></p> <p>This might give a little more info on what I'm trying to accomplish. This is my "button" with RobSiklos' changes</p> <p><img src="https://i.stack.imgur.com/82xuh.jpg" alt="Button"></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload