when filling out the MouseLeftButtonDown it promt me saying: To generate an event handler the class 'page', , specified by the x:Class or x:subclass atrribute, must be the first class in the file. Move the class code so that it is the first class in the
file and try again.
Im not sure what it means, or what i should do rather.
I found out if you put the HyperLinkButton or TextBlock as ListItem. The button's focus area is not the full length of the list item. It depend on the length of your text (it won't stretch even you set HorizontalAlignment="Stretch"). If you set a background
color to the HyperLinkButton on the ListItem you would know what I mean. The mouse cursor is another indicator when you move in/out of the Button area. So depending where you click your mouse some time it won't trigger the Click event or MouseLeftButtonDown
event.
I found by hooking the event handler to ListBox.SelectionChanged event is more reliable than using HyperLinkButton.Click or HyperLinkButton.MouseLeftButtonDown event.
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
To generate an event handler the class 'page', , specified by the x:Class or x:subclass atrribute, must be the first class in the file.
It means the partical class Page should be the first class in Page.xaml.cs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Windows.Media.Imaging;
using System.Windows.Controls.Primitives;
using System.IO;
using System.Windows.Browser;
namespace SilverlightApplication6
{
//Don't add your custom class before class Page public partial class Page : UserControl //It should be the first class
{
...
}
//Add your own class here
}
Please try again.
Regards
Sincerely,
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
FrameworkElement element = (FrameworkElement)sender;
if (element.DataContext !=
null)
System.Windows.Browser.HtmlPage.Window.Navigate(((WoWHeadSearchObject)element.DataContext).Uri,
"newwin");
}
If anyone happen to know if its posible to remove the that markup showing what item that is selected it would be nice.
Private Sub itmStudents_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles itmStudents.MouseLeftButtonDown, itmStudents.MouseLeftButtonUp
btnSubmit.Opacity = 0
txtStudent.Opacity = 0
lblStudent.Opacity = 0
Me.itmStudents.Opacity = 0
txtMessage.Text = "Please wait..."
Dim textB As TextBlock = e.Source
Dim linkB As HyperlinkButton = textB.DataContext
Dim s As String = linkB.Tag
Dim asmx2 As New ServiceReference2.GetStudentArt_WSSoapClient
AddHandler asmx2.GetStudentArtCompleted, AddressOf asmx2_GetStudentArtWithAsmxCompleted
asmx2.GetStudentArtAsync(Convert.ToInt32(linkB.Tag))
End Sub
It was working in Beta 1.
Thanks
I love computers because: MY WISH IS THEIR COMMAND :)
ListBox, ItemsControl, Button and Hyperlink Button no longer has MouseLeftButtonDown event in beta 2. That is intended change. Check beta 2 breaking change doc. You need to use Click event for Buttons. In your case, you can hookup Click event for the HyperlinkButton.
Sally Xu
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
Private Sub hlbButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
btnSubmit.Opacity = 0
txtStudent.Opacity = 0
lblStudent.Opacity = 0
Me.itmStudents.Opacity = 0
txtMessage.Text = "Please wait..."
Dim textB As TextBlock = e.Source
Dim linkB As HyperlinkButton = sender
Dim s As String = linkB.Tag
Dim asmx2 As New ServiceReference2.GetStudentArt_WSSoapClient
AddHandler asmx2.GetStudentArtCompleted, AddressOf asmx2_GetStudentArtWithAsmxCompleted
asmx2.GetStudentArtAsync(Convert.ToInt32(linkB.Tag))
End Sub
still doesn't trap.
Thanks
I love computers because: MY WISH IS THEIR COMMAND :)
Allen Chen –...
Star
14197 Points
1850 Posts
Microsoft
Re: Hyberlink button not working listbox itemtemplate
Mar 18, 2008 09:52 AM | LINK
Hi:
You can try this to work it around:
<HyperlinkButton MouseLeftButtonDown="HyperlinkButton_MouseLeftButtonDown" ...
private void HyperlinkButton_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
HyperlinkButton hb = sender as HyperlinkButton;
if (hb != null)
{
System.Windows.Browser.HtmlPage.Window.Navigate(hb.NavigateUri);
}
}
Regards
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
PoulRaider
Member
86 Points
66 Posts
Re: Hyberlink button not working listbox itemtemplate
Mar 18, 2008 11:12 AM | LINK
when filling out the MouseLeftButtonDown it promt me saying: To generate an event handler the class 'page', , specified by the x:Class or x:subclass atrribute, must be the first class in the file. Move the class code so that it is the first class in the file and try again.
Im not sure what it means, or what i should do rather.
sladapter
All-Star
43609 Points
7910 Posts
Re: Hyberlink button not working listbox itemtemplate
Mar 18, 2008 01:39 PM | LINK
PoulRaider,
I found out if you put the HyperLinkButton or TextBlock as ListItem. The button's focus area is not the full length of the list item. It depend on the length of your text (it won't stretch even you set HorizontalAlignment="Stretch"). If you set a background color to the HyperLinkButton on the ListItem you would know what I mean. The mouse cursor is another indicator when you move in/out of the Button area. So depending where you click your mouse some time it won't trigger the Click event or MouseLeftButtonDown event.
I found by hooking the event handler to ListBox.SelectionChanged event is more reliable than using HyperLinkButton.Click or HyperLinkButton.MouseLeftButtonDown event.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
PoulRaider
Member
86 Points
66 Posts
Re: Hyberlink button not working listbox itemtemplate
Mar 18, 2008 03:32 PM | LINK
Oki, is it posible in anyway to hook to an event when the mouse is over an item in the listbox.
i could do it onMouseEnter of the hyberlink, im just not sure how i would access any of the binding data for that item.
<ListBox.ItemTemplate>
<DataTemplate> <HyperlinkButton Style="{StaticResource WoWHeadLink}"> <StackPanel Orientation="Horizontal" Style="{StaticResource test}" > <Image Width="20" Height="20" Source="{Binding Icon}"/> <TextBlock Text="{Binding Text}" /> </StackPanel> </HyperlinkButton> </DataTemplate> </ListBox.ItemTemplate>Where i want to do change some other element when mouseover the hyperlink and pass the {Binding Id} to the eventhandler also.
PoulRaider
Member
86 Points
66 Posts
Re: Hyberlink button not working listbox itemtemplate
Mar 18, 2008 03:50 PM | LINK
<
tt:WoWItem x:Name="ItemToolTip"></tt:WoWItem> private void HyperlinkButton_MouseEnter_1(object sender, MouseEventArgs e){
ItemToolTip.LoadItem(((WoWHeadSearchObject)((HyperlinkButton)sender).DataContext).Id);}
Now i just need to find out how to make the position of the <tt:WoWItem x:Name="ItemToolTip"></tt:WoWItem> follow as the mouse move.
Allen Chen –...
Star
14197 Points
1850 Posts
Microsoft
Re: Hyberlink button not working listbox itemtemplate
Mar 19, 2008 01:18 AM | LINK
Hi:
It means the partical class Page should be the first class in Page.xaml.cs.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.ComponentModel;
using System.Windows.Media.Imaging;
using System.Windows.Controls.Primitives;
using System.IO;
using System.Windows.Browser;
namespace SilverlightApplication6
{
//Don't add your custom class before class Page
public partial class Page : UserControl //It should be the first class
{
...
}
//Add your own class here
}
Please try again.
Regards
Allen Chen
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
PoulRaider
Member
86 Points
66 Posts
Re: Hyberlink button not working listbox itemtemplate
Mar 19, 2008 09:00 AM | LINK
Ye found out.
So, if anyone els should run into the problem, i solved it by hooking up to the mousedown event on the stackpanel.
<DataTemplate> <StackPanel MouseLeftButtonDown="StackPanel_MouseLeftButtonDown" Orientation="Horizontal" MouseLeave="HyperlinkButton_MouseLeave" MouseEnter="HyperlinkButton_MouseEnter_1" Background="AliceBlue" Width="142" Height="22" Margin="1"> <Image Margin="0" Width="20" Height="20" Source="{Binding Icon}"/> <HyperlinkButton Foreground="#FF000000" Margin="0" Content="{Binding Text}" VerticalContentAlignment="Center" > </HyperlinkButton> </StackPanel> </DataTemplate> private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e){
FrameworkElement element = (FrameworkElement)sender; if (element.DataContext != null) System.Windows.Browser.HtmlPage.Window.Navigate(((WoWHeadSearchObject)element.DataContext).Uri, "newwin");}
If anyone happen to know if its posible to remove the that markup showing what item that is selected it would be nice.
if interested you can see an examlple of the control here: http://borkedguild.net.nhwebsrv10.needhost.dk/MenuSilverLightTestPage.aspx
yaip
Member
150 Points
151 Posts
Re: Hyberlink button not working listbox itemtemplate
Jun 18, 2008 11:14 PM | LINK
I am having the same problem but the HyperLinkButton is in ItemsControl:
<ItemsControl x:Name="itmStudents" Margin="0,0,0,0" Canvas.Top="63.287" Canvas.Left="172.2" Padding="10" >
<ItemsControl.ItemTemplate>
<DataTemplate >
<HyperlinkButton x:Name="hlbButton" FontSize="16" ></HyperlinkButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
and in my code:
Private Sub itmStudents_MouseLeftButtonDown(ByVal sender As Object, ByVal e As System.Windows.Input.MouseButtonEventArgs) Handles itmStudents.MouseLeftButtonDown, itmStudents.MouseLeftButtonUp
btnSubmit.Opacity = 0
txtStudent.Opacity = 0
lblStudent.Opacity = 0
Me.itmStudents.Opacity = 0
txtMessage.Text = "Please wait..."
Dim textB As TextBlock = e.Source
Dim linkB As HyperlinkButton = textB.DataContext
Dim s As String = linkB.Tag
Dim asmx2 As New ServiceReference2.GetStudentArt_WSSoapClient
AddHandler asmx2.GetStudentArtCompleted, AddressOf asmx2_GetStudentArtWithAsmxCompleted
asmx2.GetStudentArtAsync(Convert.ToInt32(linkB.Tag))
End Sub
It was working in Beta 1.
I love computers because: MY WISH IS THEIR COMMAND :)
<Website>
<Gadget>
sladapter
All-Star
43609 Points
7910 Posts
Re: Hyberlink button not working listbox itemtemplate
Jun 19, 2008 12:40 AM | LINK
ListBox, ItemsControl, Button and Hyperlink Button no longer has MouseLeftButtonDown event in beta 2. That is intended change. Check beta 2 breaking change doc. You need to use Click event for Buttons. In your case, you can hookup Click event for the HyperlinkButton.
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
yaip
Member
150 Points
151 Posts
Re: Hyberlink button not working listbox itemtemplate
Jun 19, 2008 01:14 AM | LINK
I changed my xaml to handle the click event as such:
<ItemsControl x:Name="itmStudents" Margin="0,0,0,0" Canvas.Top="63.287" Canvas.Left="172.2" Padding="10" >
<ItemsControl.ItemTemplate>
<DataTemplate >
<HyperlinkButton x:Name="hlbButton" FontSize="16" Click="hlbButton_Click"></HyperlinkButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
and my code-behind to:
Private Sub hlbButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
btnSubmit.Opacity = 0
txtStudent.Opacity = 0
lblStudent.Opacity = 0
Me.itmStudents.Opacity = 0
txtMessage.Text = "Please wait..."
Dim textB As TextBlock = e.Source
Dim linkB As HyperlinkButton = sender
Dim s As String = linkB.Tag
Dim asmx2 As New ServiceReference2.GetStudentArt_WSSoapClient
AddHandler asmx2.GetStudentArtCompleted, AddressOf asmx2_GetStudentArtWithAsmxCompleted
asmx2.GetStudentArtAsync(Convert.ToInt32(linkB.Tag))
End Sub
still doesn't trap.
I love computers because: MY WISH IS THEIR COMMAND :)
<Website>
<Gadget>