I am creating a custom control and have a generic.xaml page. I am trying to get the size of the buttons/other controls in the custom control. I am using a itemscontrol. I can not seem to use these in the code behind at all. Below is some xaml in my generic.xaml file and the code I tried to use in the cs file. The InitializeFromXaml always fails because it says generic.xaml is an invalid xaml file (due to its root not being a FrameworkElement).
The other solution I have would be to change the size of the buttons in my HorizontalWrapPanel. I would do this except I can not figure out how to resize a child UIElement in the panel class.
This does not work:
System.IO.Stream s = this.GetType().Assembly.GetManifestResourceStream("ClassSchedulerControls.generic.xaml");
FrameworkElement implementationRoot = this.InitializeFromXaml(new System.IO.StreamReader(s).ReadToEnd());
HorizontalWrapPanel sb = (HorizontalWrapPanel)implementationRoot.FindName("WrapSectionItems");
This is the generic.xaml default style for my control.
<Style TargetType="controls:SectionSelectControl">
<Setter Property="Width" Value="698" />
<!--<Setter Property="Height" Value="198" />-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:SectionSelectControl">
<Border BorderBrush="Black" BorderThickness="2" CornerRadius="5" HorizontalAlignment="Center" VerticalAlignment="Center">
<ScrollViewer MinWidth="698" VerticalScrollBarVisibility="Auto" >
<ItemsControl x:Name="SectionItems" ItemsSource="{TemplateBinding SectionItemsSource}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<controls:HorizontalWrapPanel x:Name="WrapSectionItems" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton Style="{StaticResource ToggleButtonStyle}" Height="{Binding Size}" Content="{Binding TestString1}"></ToggleButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>