Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You may try just not specifying a Width/Height on your UserControl. It should fit to the controls hosted within.</p> <pre><code>&lt;UserControl x:Class="MyUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;StackPanel&gt; &lt;TextBlock x:Name="TextBlock1" Text="DisplayName Goes Here" /&gt; &lt;local:TimeIntervalControl x:Name="TimeInterval" /&gt; &lt;/StackPanel&gt; &lt;/UserControl&gt; </code></pre> <p>Another option is to use an <a href="http://msdn.microsoft.com/en-us/library/system.windows.data.ivalueconverter.aspx" rel="nofollow noreferrer">IValueConverter</a> to do some heavier lifting:</p> <pre><code>&lt;UserControl x:Class="MyUserControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;UserControl.Resources&gt; &lt;local:MaxValueConverter x:Key="MaxValue" /&gt; &lt;/UserControl.Resources&gt; &lt;UserControl.Width&gt; &lt;MultiBinding Converter="{StaticResource MaxValue}"&gt; &lt;Binding Path="ActualWidth" ElementName="TextBlock1" /&gt; &lt;Binding Path="ActualWidth" ElementName="TimeInterval" /&gt; &lt;/MultiBinding&gt; &lt;/UserControl.Width&gt; &lt;StackPanel&gt; &lt;TextBlock x:Name="TextBlock1" Text="DisplayName Goes Here" /&gt; &lt;local:TimeIntervalControl x:Name="TimeInterval" /&gt; &lt;/StackPanel&gt; &lt;/UserControl&gt; </code></pre> <p>Heavy lifting in your MaxValueConverter:</p> <pre><code>public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (values == null) { return Binding.DoNothing; } return values.Max(obj =&gt; (obj is double) ? (double)obj : 0.0); } </code></pre>
 

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