|
I think I see what you mean.
I know that the static class does not have to be instantiated...
How can I place the value inside this static class so that it gets passed to page2.xaml from page1.xaml ?
Do you mean to create a static class and add property get and set for each parameter name?
I tried it and seems to work. I always thought in silverlight you pass parameters between pages as in asp.net which is like ?value1=xyz&value=sas...
Thanks
modified on Thursday, March 31, 2011 11:30 AM
|
|
|
|
|
Suppose that you want something a little bit more complicated:
public class MyModel
{
public string ForeName { get; set; }
public string Surname { get; set; }
} Well, you could have a class - we'll call it NavigationManager - that looks like this:
public static NavigationManager
{
static NavigationManager()
{
Page1Model = new MyModel{ ForeName = string.Empty, Surname=string.Empty };
}
public MyModel Page1Model { get; set; }
} Then, setting your values is as simple as:
NavigationManager.Page1Model.ForeName = myForename;
NavigationManager.Page1Model.Surname = mySurname; Retrieving the data from another page is just as trivial (although I'd prefer to use the ViewModel on both sides rather than code behind).
|
|
|
|
|
I have now created a static class with static properties.
Placed the properties inside the class with get and set.
page1 sets the value of the property and then navigates to page2.
page2 reads the property from the static class.
Is this method in silverlight more efficient or better than the asp.net method which was like &value1=xyz&value2sdd... and request.param[value1]... ?
Thanks
|
|
|
|
|
Well, one of the issues with the ASP.NET way of doing things is you lost type safety with the parameters. Effectively they were strings. If, also, your parameter name was slightly different on both sides, then you'd never get the value.
|
|
|
|
|
|
Hello,
I have a window with a listbox bound to a User table in a DataSet, which displays the userid column:
<Window Name="ParentWindow" ...>
....
<ListBox Name="listBoxUsers" ItemsSource="{Binding User}"
SelectionChanged="listBoxUsers_SelectionChanged"
SelectedItem="{Binding ElementName=ParentWindow,Path=CurrentUser,Mode=OneWayToSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=userid}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I managed to bind the current selection to a DataRowView property in the window:
public DataRowView CurrentUser
{
set
{
System.Diagnostics.Trace.WriteLine(value);
}
}
However, I'd like to bind to a string property:
public string CurrentUser
{
set; private get;
}
...so that I can read the currently selected userid easily via getCurrentUser().
Is that feasible ?
Thanks,
J-L
-- Modified Thursday, March 31, 2011 11:16 AM
|
|
|
|
|
Is CurrentUser as row?
If so then simply get the column value from the datarow. You may need another property or you may be able to bind to required columns value.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
In design view, I can see the image control populated with the image file, but the image is not shown at run time.
Any thoughts please?
This is the xaml I am using:
<Image Name="myLogo" Source="/images/logo_my.png" Grid.Column="0" Grid.Row="0"
Stretch="Fill"/>
|
|
|
|
|
My first thought is that the image is not linked properly to your Xap. In other words, you haven't set the type to Content and set CopyToOutputDirectory. If you open up your Xap, you'll find that the image is not there (An Xap is just a zipped format, so you can rename it to zip and open it up).
|
|
|
|
|
Working now.
Well done.
Thanks
|
|
|
|
|
|
arkiboys
May I make a suggestion, Pete answers a lot of our questions with very useful info, it is polite to up vote his response when it meets your approval. While the vote could come from someone else I suggest you use the voting to thank him.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
ok, thanks
Solved.
modified on Thursday, March 31, 2011 11:15 AM
|
|
|
|
|
Thanks mate. As long as there's a SOLVED somewhere to indicate that the issue is resolved, that's the main thing. As he always thanks me, I'm happy with that - and I'll always upvote a thanks.
|
|
|
|
|
Pete O'Hanlon wrote: As he always thanks me
Sure the guy is polite and appreciative but quite possibly does not realise that an upvote has value unto itself.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Well, I don't think he's going to have that much of an overall effect on my reputation
|
|
|
|
|
Hi,
I am using silverlight 4.
My project has navigation frame.
page1.xaml has a datagrid which can sometimes have many records.
If the datagrid in page1.xaml has many records, then I do not see the records at the bottom of the datagrid. And there is no scrollbar to scroll to the bottom of the data in the datagrid.
Can you see what is wrong with this xaml in the mainpage.xaml please?
<Border Margin="10,10,10,12" Padding="10" BorderBrush="DarkGray" BorderThickness="2"
CornerRadius="4" Grid.Row="1" Grid.Column="1">
<navigation:Frame x:Name="mainFrame" UriMapper="{StaticResource UriMapper}"
Source="Home" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" >
</navigation:Frame>
</Border>
Thank you
modified on Thursday, March 31, 2011 4:16 AM
|
|
|
|
|
Wrap navigation:Frame in a ScrollViewer panel.
|
|
|
|
|
|
|
Hi,
I have a page on a windows phone 7 app, that I want to be able to click to specific button say a "Message" button and it would navigate to the Message panorama item on another panorama page.
How would I go about navigating to a specific panorama item?
Thanks
|
|
|
|
|
Anyone know how to style a Telerik RadRadioButton so that it works like MS Office Ribbon buttons? When you select a button, or hover over it, I want to see the button's gradient color and border. When not selected or hovered over, I want to button to not show the effect.
Telerik's help isn't too helpful. Google didn't help either.
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
You just need to modify the control template and add a MouseOver trigger the same as you would any other control. If they don't give you the XAML templates, you can dump them out with Blend.
|
|
|
|
|
OK - and I though this one was going to be easy!
I want a text box in a WPF form into which the user can enter a currency amount (e.g. $12.34)
I want to be able to give them an error message if they type in rubbish (e.g. "freds cash")
I want to be able to validate for ranges (so they can't for example, enter -ve numbers )
My 1st thought was to bind a standard textbox to my data property, which is a Decimal?, which doesn't work very well, as if the user types rubbish, an exception is thrown which (as far as I can ascertain) I can't catch!) I know I can display an error message/highlight the control if this happens, but this means that what is shown on the screen doesn't match what is in the property that I'm binding to - so what happens if the user now clicks the SAVE button? it saves the 'old' value, not what's on the screen, that's what!
Solutions I have seen include only binding to strings, and then validating the user input in the setter of those strings. Josh Smith does this here[^] While I like this idea, I feel a little uncomfortable - I'd really like to bind to the 'real' data and not a string representation of it.
Other solutions I came across included karl's solution here[^] which looks very interesting.
But I figure, WPF has been around for a while, so surely there's some accepted way of entering monetary amounts?
Am I missing something really obvious, so obvious that nobody's blogging about it? Or, am I just crap at Googling? Or, do I need to look at Josh or Karl's solution and use one of them? Or, is there a better way?
|
|
|
|
|
You need an attached behavior for this. I wrote one for Goldlight that effectively looks like this:
namespace Goldlight.Behaviors
{
using System.Windows;
using System.Windows.Interactivity;
using System.Windows.Input;
using System.Windows.Controls;
using System.Text.RegularExpressions;
public class NumericTextBoxBehavior : Behavior<TextBox>
{
#region Overrides
protected override void OnAttached()
{
base.OnAttached();
AssociatedObject.PreviewTextInput += AssociatedObject_PreviewTextInput;
DataObject.AddPastingHandler(AssociatedObject, OnClipboardPaste);
}
protected override void OnDetaching()
{
AssociatedObject.PreviewTextInput -= AssociatedObject_PreviewTextInput;
DataObject.RemovePastingHandler(AssociatedObject, OnClipboardPaste);
}
#endregion
#region Private Methods
private void AssociatedObject_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
var tb = AssociatedObject;
e.Handled = !Validate(e.Text);
}
private void OnClipboardPaste(object sender, DataObjectPastingEventArgs e)
{
var tb = sender as TextBox;
string text = e.SourceDataObject.GetData(e.FormatToApply) as string;
if (!string.IsNullOrEmpty(text) && !Validate(text))
{
e.CancelCommand();
}
}
private bool Validate(string newContent)
{
TextBox tb = AssociatedObject;
string testString = string.Empty;
string pre = string.Empty;
string post = string.Empty;
if (!string.IsNullOrEmpty(tb.SelectedText))
{
pre = tb.Text.Substring(0, tb.SelectionStart);
post = tb.Text.Substring(tb.SelectionStart + tb.SelectionLength,
tb.Text.Length - (tb.SelectionStart + tb.SelectionLength));
}
else
{
pre = tb.Text.Substring(0, tb.CaretIndex);
post = tb.Text.Substring(tb.CaretIndex, tb.Text.Length - tb.CaretIndex);
}
testString = pre + newContent + post;
Regex regExpr = new Regex(@"^([-+]?)(\d*)([,.]?)(\d*)$");
return (regExpr.IsMatch(testString));
}
#endregion
}
} The full Goldlight version does quite a bit more with the regex, but this basic logic holds. Now, all you need to do is attach this to your TextBox .
|
|
|
|