I have a SilverLight Page and within this page I have an XamWebOutlookBar with two OutlookBarGroups in it, inside each of the groups I have different controls including a ComboBox. Before changing my code to use the XamWebOutlookBar the instance of the ComboBox was used inside my page's constructor to set its ItemsSource to a list of strings. as follows.
List<string> list = new List<string>();
list.Add("Item 1");
list.Add("Item 2");
cboxReasons.ItemsSource = list;
And of course the cboxReasons is references other places in the C# code. Now that I've put this ComboBox inside a group in XamWebOutlookBar, its always NULL and I keep hitting a NullReferenceException. I also tried setting the ComboBox's items in the design level (XAML), thinking XamWebOutlookBar instantiates it in a later stages, but the instance is still NULL.
Any help on how to add/set a ComboBox in the XamWebOutlookBar is appreciated.
The following is my XAML.
<navigation:Page
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"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
xmlns:controls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:controlsToolkit="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Toolkit"
xmlns:igHtmlViewer="clr-namespace:Infragistics.Silverlight.Controls;assembly=Infragistics.Silverlight.XamWebHtmlViewer.v9.2"
xmlns:igOB="clr-namespace:Infragistics.Silverlight.Controls;assembly=Infragistics.Silverlight.XamWebOutlookBar.v9.1"
x:Class="PCRViewerSLite.Views.PcrSearch"
d:DesignWidth="640" d:DesignHeight="480"
Title="PCR Viewer">
<navigation:Page.Resources>
<DataTemplate x:Key="ViewButtons">
<StackPanel Orientation="Horizontal">
<Button x:Name="btnViewLegalPcr" Tag="{Binding}" Click="btnLegalView_Click" ToolTipService.ToolTip="View Legal Info" Style="{StaticResource Action_Button_Style}">
<Image Margin="0" Height="20" Width="20" Source="/PCRViewerSLite;Component/Images/Medical_Report_Legal.png"/>
</Button>
<Button x:Name="btnViewPcrDetails" Tag="{Binding}" Click="btnPcrDetails_Click" ToolTipService.ToolTip="View PCR" Style="{StaticResource Action_Button_Style}">
<Image Margin="0" Height="20" Width="20" Source="/PCRViewerSLite;Component/Images/Medical_Report_Full.png"/>
</StackPanel>
</DataTemplate>
</navigation:Page.Resources>
<Grid x:Name="LayoutRoot" Background="{StaticResource Theme_Color1}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<igOB:XamWebOutlookBar>
<igOB:OutlookBarGroup x:Name="groupSearch" Header="Search" IsSelected="True">
<igOB:OutlookBarGroup.LargeIconTemplate>
<DataTemplate>
<Image Margin="0" Height="20" Width="20" Source="/PCRViewerSLite;Component/Images/Find.jpg"/>
</igOB:OutlookBarGroup.LargeIconTemplate>
<ScrollViewer x:Name="scrollViewSearch" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" VerticalAlignment="Top" controlsToolkit:DockPanel.Dock="Top">
<Grid x:Name="gridSearch" Background="{StaticResource NavigationForegroundColorBrush}" Margin="0" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontSize="9.333" FontStyle="Italic" Text="Include close matches:" Grid.Row="1" d:LayoutOverrides="Height, GridBox"/>
<CheckBox x:Name="checkBoxCloseMatch" Content="" Grid.Column="1" Grid.Row="1" d:LayoutOverrides="Height" FontSize="9.333" ToolTipService.ToolTip="Using this option will increase search times">
<CheckBox.Effect>
<DropShadowEffect BlurRadius="0"/>
</CheckBox.Effect>
</CheckBox>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontSize="9.333" FontStyle="Italic" Text="County:" Grid.Row="2" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center" FontWeight="Bold"/>
<ComboBox x:Name="cboxCounties" Grid.Column="1" Grid.Row="2" d:LayoutOverrides="Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="Case Number:" Grid.Row="3" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtCaseNumber" Grid.Column="1" Grid.Row="3" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="Patient First Name:" Grid.Row="4" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtFirstName" Grid.Column="1" Grid.Row="4" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="Patient Last Name:" Grid.Row="5" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtLastName" Grid.Column="1" Grid.Row="5" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="Patient DOB:" Grid.Row="6" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtDob" Grid.Column="1" Grid.Row="6" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="Unit:" Grid.Row="7" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtUnit" Grid.Column="1" Grid.Row="7" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="From Date of Service:" Grid.Row="8" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left"/>
<controls:DatePicker x:Name="datePickerFrom" d:LayoutOverrides="Width, Height" Grid.Row="8" Grid.Column="1"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="To Date of Service:" Grid.Row="9" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left"/>
<controls:DatePicker x:Name="datePickerTo" Grid.Column="1" Grid.Row="9" d:LayoutOverrides="Width, Height"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="From Address:" Grid.Row="10" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtFromAddress" Grid.Column="1" Grid.Row="10" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Foreground="Black" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="To Address:" Grid.Row="11" d:LayoutOverrides="Height, GridBox" HorizontalAlignment="Left" VerticalAlignment="Center"/>
<TextBox x:Name="txtToAddress" Grid.Column="1" Grid.Row="11" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" FontSize="9.333" HorizontalAlignment="Left" MinWidth="150"/>
<Button x:Name="btnSearch" ClickMode="Press" RenderTransformOrigin="0.717,3.773" Click="btnSearch_Click" VerticalAlignment="Center" Width="50" Height="20" HorizontalAlignment="Left" Content="Search" FontSize="9.333" Grid.Row="14" d:LayoutOverrides="HorizontalAlignment"/>
</Grid>
</ScrollViewer>
</igOB:OutlookBarGroup>
<igOB:OutlookBarGroup x:Name="groupResults" Header="Results">
<Image Margin="0" Height="20" Width="20" Source="../Images/action_detail.png"/>
<ScrollViewer x:Name="scrollViewResults" VerticalScrollBarVisibility="Auto"
controlsToolkit:DockPanel.Dock="Left" HorizontalScrollBarVisibility="Auto" FontSize="9.333" HorizontalContentAlignment="Left" VerticalContentAlignment="Top" Height="0" Width="270" d:LayoutOverrides="VerticalAlignment">
<StackPanel>
<TextBlock TextWrapping="Wrap" Foreground="White" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="Select from a list:" Height="14"/>
<ComboBox x:Name="cboxReasons" DisplayMemberPath="" SelectionChanged="cboxReasons_SelectionChanged" FontSize="9.333" MinWidth="150" Height="18">
<ComboBoxItem Height="100" Width="100" Content="Item 1" IsSelected="True"/>
<ComboBoxItem Height="100" Width="100" Content="Item 2"/>
</ComboBox>
<TextBlock TextWrapping="Wrap" Foreground="White" FontWeight="Bold" FontSize="9.333" FontStyle="Italic" Text="Or type a reason here:" d:LayoutOverrides="GridBox" HorizontalAlignment="Left" Height="14"/>
<TextBox x:Name="txtTypedReason" Background="#FF0097FC" Foreground="White" MinWidth="150" CaretBrush="White" TextWrapping="Wrap" ToolTipService.ToolTip="Enter your login user name" HorizontalContentAlignment="Left" VerticalContentAlignment="Stretch" FontSize="9.333" Height="22" HorizontalAlignment="Left" d:LayoutOverrides="Height"/>
<data:DataGrid x:Name="dataGridResults" GridLinesVisibility="All" SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" IsReadOnly="True" AutoGenerateColumns="True">
<data:DataGrid.Columns>
<data:DataGridTemplateColumn CellTemplate="{StaticResource ViewButtons}"/>
</data:DataGrid.Columns>
</data:DataGrid>
</igOB:XamWebOutlookBar>
<igHtmlViewer:XamWebHtmlViewer x:Name="htmlViewer" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto" Grid.Column="1" d:LayoutOverrides="Width, Height" Background="{StaticResource Theme_Color1}"/>
</navigation:Page>
The same thing happens when the DataGrid instance is referenced in the code to populate its ItemsSource.
It seems like XamWebOutlookBar is not instantiating its controls, or is there a magical way to do that that's not documented?
Thanks,
Ninos
Hi gsarkis / Ninos
This behavior is by design. As a workaround, you could use an approach which is demonstrated by the following sample:
<UserControl x:Class="TestApp.Groups" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:w="clr-namespace:System.Windows;assembly=System.Windows" xmlns:igOB="clr-namespace:Infragistics.Silverlight.Controls;assembly=Infragistics.Silverlight.XamWebOutlookBar.v9.1" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid x:Name="LayoutRoot"> <igOB:XamWebOutlookBar x:Name="MyOutlookBar"> <igOB:OutlookBarGroup Key="ComboGroup"> <ComboBox> <ComboBoxItem Content="ComboItem1"/> <ComboBoxItem Content="ComboItem2"/> </ComboBox> </igOB:OutlookBarGroup> </igOB:XamWebOutlookBar> </Grid></UserControl>
public partial class Groups : UserControl { public Groups() { InitializeComponent();
ComboBox myCombo = null;
myCombo = this.MyOutlookBar.Groups["ComboGroup"].Content as ComboBox; } }
I hope this will solve your issue and no inconvenience will be caused.
Regards,