I need help adding a ScrollViewer to a list on controls added at run time. With up to 50 rules being added in the code behind the top position on the canvas exceeds its design time size, and a scrolling view of the rules is necessary
I am adding a number of controls to a canvas at run time. The position on the canvas is determined at run time. When the number of controls forces the Canvas.SetTop(control, topPosition) to use a topPosition greater than the Canvas.Height property I want a scrollbar to appear.
I have added the ScrollViewer outside of the Canvas declaration. The ScrollViewer is visible, but appears disabled.
This is the XAML
<GroupBox Name="QuickPickEntryCountGroupBox" Width="170" BorderThickness="0" Margin="190,751,0,0" >
<ScrollViewer Name="QpRulesScrollViewer" VerticalScrollBarVisibility="Visible" CanContentScroll="True" >
<Canvas Name="QPRulesCanvas" Height="50" Width="170" MaxHeight="130">
</Canvas>
</ScrollViewer>
The code behind is
foreach (var QPcount in dataAccess.pprqpdtab)
{
try
{
var pr = dataAccess.qta.spFetchPromoRuleEntryCount(promoGameId, promoDrawNumber, QPcount.Games);
ruleEntryCount = 0;
ruleGamesChecked = false;
if (pr != null)
{
ruleEntryCount = (int) pr;
ruleGamesChecked = true;
}
}
catch (Exception eRule)
{
exception handler code
}
var QPOption = new STDQPOptions(QPcount.Games, (int)ruleEntryCount, ruleGamesChecked);
placeElement(QPOption, leftpos, toppos);
toppos += 20;
}
</pre>
Where placeElement(QPOption, leftpos, toppos)
is
<pre lang="cs">public void placeElement(UIElement control, int leftPosition, int topPosition)
{
QPRulesCanvas.Children.Add(control);
Canvas.SetLeft(control, leftPosition);
Canvas.SetTop(control, topPosition);
}</pre>