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
Hello,
Please add the click event to the XAML as follows:
<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" Click="Button1_Click" /> <HyperlinkButton Content="HyperlinkButton" Height="35" Name="HyperlinkButton1" Width="100" Click="HyperlinkButton1_Click" /> </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>
Let me know if you have any questions.
Valerie
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.
Regards,
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().
<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
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.
Sorry for the delayed response. It did work perfectly as expected.
Thank you very much,
This is a follow-up to see if you have any questions about capturing a click event.
Thank you,Sam
Basically you have a collection of Groups in the Outlookbar. You need to give each Group a key so then you can later find that group. Once you've found the group, you can grab the control you looking for.
1.) You need to extend you Xaml to include Keys for each group:
<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" Key="ouGroup1" VerticalAlignment="Stretch" > <ContentControl> <StackPanel> <Button Content="Button" Height="23" Name="Button2" Width="75" Click="Button2_Click" /> </StackPanel> </ContentControl> </ig:OutlookBarGroup> <ig:OutlookBarGroup Header="Stock" HorizontalAlignment="Stretch" Margin="0" Name="OutlookBarGroup2" Key="ouGroup2" VerticalAlignment="Stretch" > <ContentControl> <ig:XamTree Height="100" Name="XamTree1" Width="200" >
</ig:XamTree> </ContentControl> </ig:OutlookBarGroup> </ig:XamOutlookBar>
2.) Then in the code behind, grab the proper group, and then look for your Tree:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
Dim tvItem As XamTreeItem = New XamTreeItem
'We can use the key from the Xaml to get our group Dim ouBar2 = XamOutlookBar1.Groups("ouGroup2")
If (ouBar2 Is Nothing) Then Return End If
'Now we can check that instance of the group to find our control Dim xamTree1 = ouBar2.FindName("XamTree1")
If (xamTree1 Is Nothing) Then Return End If
tvItem.Name = "itm1" tvItem.Header = "Item1" xamTree1.Items.Add(tvItem)
End Sub
Hope that helps,Thanks,Rich
Modifying a little. by replacing the XamTree from OutlookBarGroup1 to OutlookBarGroup2 gives the same error. Can you please let me know how do I get the Instance of the control in this case.
Thank you,
<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" /> </StackPanel> </ContentControl> </ig:OutlookBarGroup> <ig:OutlookBarGroup Header="Stock" HorizontalAlignment="Stretch" Margin="0" Name="OutlookBarGroup2" VerticalAlignment="Stretch" > <ContentControl> <ig:XamTree Height="100" Name="XamTree1" Width="200" > </ig:XamTree> </ContentControl> </ig:OutlookBarGroup> </ig:XamOutlookBar>
Thanks a lot, that worked.