Has this been removed from silverlight 3?
http://msdn.microsoft.com/en-us/library/ms598899%28VS.95%29.aspx
I see documentation on how to use it, but when I try it says UIElement doesn't have an addhandler method
Hm, seems to work for me..
UIElement asdf = new Canvas();
asdf.AddHandler(ucConveyor.MouseLeftButtonDownEvent, TestFunction, false);
Can you paste your code?
Related
I am new to WPF, here I am making a jigsaw game but encountering a problem: I just don't know how to let a image show in a Label in pure code (in XAML, I can do it.), I have searched google a lot but seems that no releated articles regarding this topic. Anyone can help me on this? thx.
My Code Sample:
Label lbl = new Label();
lbl.Width = 120;
lbl.Height = 120;
lbl.Background = new SolidColorBrush(Colors.YellowGreen);
BitmapImage myImageSource = new BitmapImage();
myImageSource.BeginInit();
myImageSource.UriSource = new Uri("Images/test.png",UriKind.Relative);
myImageSource.EndInit();
lbl.Background.SetValue(ImageBrush.ImageSourceProperty, myImageSource);
myGridContainer.Children.Add(lbl);
well, this code sample can't work. why ? any comment or answer from you will be appreciated , thx.
You can use BindingOperations.SetBinding to data-bind a DependencyProperty to its source.
See also: How can I create a tiled image in code that is also data-bound?
I've tried to change the culture to es-es in the code behind of the main window
public MainWindow()
{
InitializeComponent();
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-es");
}
and got this error :
Cannot locate resource 'panelview.baml'.
while panelview is a user control that i'm using in the main window.
Can someone guess what is the problem ?
Try
Thread.CurrentThread.CurrentUICulture = new CultureInfo("es-ES");
Did you the NeutralResourcesLanguage attribute in your AssemblyInfo, similar to this?
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
If yes, try removing that line and see if that works.
Had a similar issue where the application would search for an satellite assembly that wasn't there.
Another way to fix this could be to have an resource file for es-ES.
Try calling another page from MainWindow and see if changes would appear in that page. MainWindow won't reflect.
Is there a way to create a mailto: hyperlink in a Silverlight 4 OOB app? Thanks!
Edit: based on some of the discussion, an acceptable answer would be a different way than using the HyperlinkButton, or a way to use the HyperlinkButton without having the extra popup in IE.
Ideally it would have been nice of you to post some code, as I have no idea whether the email address is known/determined at design-time or run-time, but nonetheless:
In XAML:
<HyperlinkButton x:Name="mailButton" NavigateUri="mailto:somedude#example.com" TargetName="_blank"></HyperlinkButton>
In C#:
HyperlinkButton hbtn = new HyperlinkButton();
hbtn.Name = "mailButton";
hbtn.TargetName = "_blank";
hbtn.NavigateUri = new Uri("mailto:somedude#example.com");
parent.Controls.Add(hbtn);
In a situation in which you don't know the email address at design time, it's relatively straightforward to assign the value of the NavigateUri property within a method.
I posted a solution to this issue on CodeProject
http://www.codeproject.com/Answers/383879/Silverlight-mailto-HyperlinkButton-always-opens-an#answer2
Essentially, instead of using the default behaviour add a click event and then call javascript location.href. This stops the extra browser window opening.
private void TestLink_Click(object sender, RoutedEventArgs e)
{
//Only run the click event if in browser because this will not work OOB
if (Application.Current.IsRunningOutOfBrowser)
return;
var cmd = String.Format("location.href='mailto:test#test.com?subject=blah&body=something';",
HtmlPage.Window.Eval(cmd);
}
I ham developing an application for WP7 and i am having a strange problem with Image control, it does not show the image it is binded to.
I have tryed it in so many ways but event this way (the most naive one) does not work:
In the xaml I have an Image control named img and this is what I have done in the code behind
public MainPage()
{
InitializeComponent();
img.Source = new BitmapImage(new Uri (#"http://img11.imageshack.us/img11/5365/photovnj.jpg", UriKind.Absolute));
}
</code>
It seems to simple not to work...
Please help!
This code works fine for me presuming you have img declared as an Image in your xaml.
If not, I'd suggest you have a connection problem from your app running in the emulator or device to the internet.
This is the code I wrote.
image1.Source = new BitmapImage(new Uri(#"http://img11.imageshack.us/img11/5365/photovnj.jpg", UriKind.Absolute));
The problem is that I need to change Label FontWeight and FontStyle programmatically but nothing seems to work... this is what I've tried so far:
label.FontWeight = FontWeight.FromOpenTypeWeight(99);
For label.FontStyle I have no idea, I got stuck here:
label.FontStyle = new FontStyle();
I have no idea what to do from there on. I googled like crazy but found nothing.
Thanks in advance for any suggestion!
For FontStyle you can use the FontStyles class in the code-behind, and for FontWeight use the FontWeights.
private void Button_Click(object sender, RoutedEventArgs e)
{
uiLabel.FontWeight = FontWeights.Bold;
uiLabel.FontStyle = FontStyles.Italic;
}
Take a look at this SO question. It doesn't help with the label, per se, but it does allow you to change properties of the text using a TextBlock control.