Hi,
I want to capture the events of controls placed inside the Outlookbar, which I cannot with the following code.
Please correct me if there is something going wrong in my code.
Thanks
Irfan
Xaml:
<Grid x:Name="LayoutRoot" Background="White"> <StackPanel Orientation="Horizontal" x:Name="StackPnl1"> <ig:XamOutlookBar HorizontalAlignment="Left" Height="400" Margin="10,10,0,0" Name="XamOutlookBar1" VerticalAlignment="Top" Width="200"> <ig:OutlookBarGroup Header="Sales" HorizontalAlignment="Stretch" Margin="0" Name="OutlookBarGroup1" VerticalAlignment="Stretch" > <ContentControl> <StackPanel> <Button Content="Button" Height="23" Name="Button1" Width="75" /> <HyperlinkButton Content="HyperlinkButton" Height="35" Name="HyperlinkButton1" Width="100" /> </StackPanel> </ContentControl> </ig:OutlookBarGroup> <ig:OutlookBarGroup Header="Stock" HorizontalAlignment="Stretch" Margin="0" Name="OutlookBarGroup2" VerticalAlignment="Stretch" > <ContentControl> </ContentControl> </ig:OutlookBarGroup> </ig:XamOutlookBar> <sdk:Label Height="28" Name="Label1" Width="120" /> </StackPanel> </Grid>
Xaml.vb:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click Label1.Content = "Clicked" End Sub Private Sub HyperlinkButton1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles HyperlinkButton1.Click Label1.Content = "Clicked" End Sub
To fix that you just need to find the instance of the control from it's parent. Modify your click handler like so:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim tvItem As XamTreeItem = New XamTreeItem
'Find the control from inside the parent. Dim xamTree1 = XamOutlookBar1.FindName("XamTree1") tvItem.Name = "itm1" tvItem.Header = "Item1" xamTree1.Items.Add(tvItem)
End Sub
I hope that helps, Best of luck,
Rich
In another project I am facing a problem while adding a dynamic control to the XamOutlookBar. For example I am adding a XamTreeItem to a XamTree placed inside the XamOutlookBar by clicking a HyperlinkButton which is also inside the XamOutlookBar. While adding the control I get the same error "Object reference not set to an instance of an object."
Please let me know how to solve this.
Thanks,
<ig:XamOutlookBar HorizontalAlignment="Left" Height="400" Margin="10,10,0,0" Name="XamOutlookBar1" VerticalAlignment="Top" Width="200"> <ig:OutlookBarGroup Header="Sales" HorizontalAlignment="Stretch" Margin="0" Name="OutlookBarGroup1" VerticalAlignment="Stretch" > <ContentControl> <StackPanel> <Button Content="Button" Height="23" Name="Button2" Width="75" Click="Button2_Click" /> <ig:XamTree Height="100" Name="XamTree1" Width="200" > </ig:XamTree> <StackPanel Height="100" Name="StackPanel1" Width="200" /> </StackPanel> </ContentControl> </ig:OutlookBarGroup> </ig:XamOutlookBar>
Xaml.vb
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Dim tvItem As XamTreeItem = New XamTreeItem tvItem.Name = "itm1" tvItem.Header = "Item1" XamTree1.Items.Add(tvItem) End Sub
Hello Irfan,
You should use the FindName method to find the button first ant after taht you could get it's properties. Inside you button event handler you could use the following code :
Dim
tb As String
Button2 = XamOutlookBar1.FindName(
"Button2")
tb = Button2.Content.ToString
which will help you. If you are having any question please feel free to ask!
Regards, Nikola.
Hello,
Getting one more problem. for example if I have two buttons inside the OutlookBar, I can not get the properties of one control the click event of the other control, for example with the following code getting the error "Object reference not set to an instance of an object." on Button1_Click().
Regards,
<ig:XamOutlookBar HorizontalAlignment="Left" Height="400" Margin="10,10,0,0" Name="XamOutlookBar1" VerticalAlignment="Top" Width="200"> <ig:OutlookBarGroup Header="Sales" HorizontalAlignment="Stretch" Margin="0" Name="OutlookBarGroup1" VerticalAlignment="Stretch" > <ContentControl> <StackPanel> <Button Content="Button" Height="23" Name="Button1" Width="75" Click="Button1_Click" /> <Button Content="Button" Height="23" Name="Button2" Width="75" Click="Button2_Click" /> </StackPanel> </ContentControl> </ig:OutlookBarGroup> </ig:XamOutlookBar>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click Dim tb As String tb = Button2.Content End Sub
Thanks for your time and effort. In my sample the code Click="Button1_Click" and Click="HyperlinkButton1_Click" has not been generated in the Xaml but in xaml.vb. Now its working fine after I write 'Click' event in Xaml.