Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Automatic resizing of User Control after adding content programmatically

$
0
0

I have a user control (UC) that is placed on a Canvas at runtime. The XAMl looks like this:

<UserControl x:Class="GVWpfRenderingEngineStandard.RadioButtonsUC" 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:GVWpfRenderingEngineStandard"
             mc:Ignorable="d" d:DesignHeight="70" d:DesignWidth="150"><Border Name="Br_Frame" BorderThickness="5" CornerRadius="4"><DockPanel Background="{Binding ChValBackground}"><GroupBox Header="{Binding ChannelName}" Margin="3"><WrapPanel Name="WP_Buttons" Orientation="Horizontal"/></GroupBox></DockPanel></Border></UserControl>

The UC starts very small as there is nothing but an empty GroupBox on it (with a default header). After some user configuration, a number of RadioButtons are added in code (C#) to the WrapPanel and the dependency property bound to the WrapPanel gets a new value - nothing else:

EnumRB = new Dictionary<int, RadioButton>();
foreach(KeyValuePair<int, string> EV_KVP in ChannelRef.GetUnderlyingType())
{
  EnumRB[EV_KVP.Key] = new RadioButton();
  EnumRB[EV_KVP.Key].Content = EV_KVP.Value;  // For the header content
  EnumRB[EV_KVP.Key].Tag = EV_KVP.Key; // For the enumeration value
  EnumRB[EV_KVP.Key].Checked +=new RoutedEventHandler(OnValueChange);
  EnumRB[EV_KVP.Key].Margin = new Thickness(8);
  WP_Buttons.Children.Add(EnumRB[EV_KVP.Key]);
}

The size of the UC does not change in response to that operation. If the user resized the UC, the content is revealed and it looks as expected. However, I'd like my UC to automatically resize itself after the content has been added. What is an elegant way for achieving that? I'd like a solution in the XAML but I'd resort to code-behind, if necessary.

Kamen


Currently using Visual Studio 2010 SP1, native C++ (Windows API) and C# (.Net, WPF), on Windows 7 64-bit; Mountain Time zone.



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>