|
It turns out that the link does not actually help me, I don't expose the url eg www.corporate.com?companyid=1 However I guess I should be able to use mymapper to hard code the url. Pick up www.corporate.com/CompanyName in mymapper and deal with it.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The domain "www.corporate.com" doesn't need to be in the code, does it?
According to your original post, you should only need something like this
<navigation:Frame.UriMapper>
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="/Company1" MappedUri="/Views/Company1.xaml"/>
<uriMapper:UriMapping Uri="/Company2" MappedUri="/Views/Company2.xaml"/>
<uriMapper:UriMapping Uri="/Company3" MappedUri="/Views/Company3.xaml"/>
<uriMapper:UriMapping Uri="/Company4" MappedUri="/Views/Company4.xaml"/>
</uriMapper:UriMapper>
</navigation:Frame.UriMapper>
or better yet, to not hard-code company names in the code...
<navigation:Frame.UriMapper>
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
</uriMapper:UriMapper>
</navigation:Frame.UriMapper>
Mark Salsbery
Microsoft MVP - Visual C++
modified on Wednesday, May 25, 2011 4:36 PM
|
|
|
|
|
How do you eliminate the # requirement. Currently the nav wants
www.Corporate.com/#Company1
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If you create and build a SIlverlight Navigation Application from the visual Studio project templates and run it, you'll see there's no "#" requirement.
I'm not sure where that would come from
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mycroft Holmes wrote: I know I can change skins (never having built a skin this is an assumption
Good assumption - yes you can[^].
The funniest thing about this particular signature is that by the time you realise it doesn't say anything it's too late to stop reading it.
|
|
|
|
|
Hi all,
I am still digging into WPF and last night have a look around with User Controls.
If I said that User Controls are more likely the templates, where I can reuse later time, what you think? Any comments really appreciate.
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
I personally would not associate UserControl with the word "template" in WPF/Silverlight, since a "template" in these frameworks has a specific meaning.
Some info on UserControls compared to other controls... Control Authoring Overview[^]
*edit* fixed link
Mark Salsbery
Microsoft MVP - Visual C++
modified on Wednesday, May 25, 2011 5:06 AM
|
|
|
|
|
Thanks for the reply.
May be that I have not enough experience with WPF. I agreed with you, comparing with ASP.Net and so on, word template is not relevant. Basically it has a different meaning.
Why I wonder is that I can use the same XAML in different places as well. Is there anything in WPF named as 'templates' ?
Thanks for the link as well, sounds good it is.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
CodingLover wrote: Is there anything in WPF named as 'templates' ?
Oh yes!
Styles and Templates[^]
(fixed link in post above)
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote: Oh yes!
Let see, still I'm working on with user controls.
Mark Salsbery wrote: (fixed link in post above)
Thanks
I appreciate your help all the time...
CodingLover
|
|
|
|
|
Hi,
I am new to MVVM and trying to implement it in my application.
I have a develop a GUI which will interact with the Hardware through some protocol. This is first experience under this space.
Just to keep things simple, consider I have a hardware which contains Voltage and Resistance parameter at different sections of the hardware.
View
----
So, I have total 5 sections. Each of them contains 15 different Voltages and Resistance.
In my WPF GUI, I am representing these 5 sections in a tab control.
I have created a user control(PowerControl) that contains 2 sliders for Voltage and Resistance. Voltage varies from 0-120v and Resistance varies from 1-10 ohm.
Each of the sections in the tab control contains 15 user controls.
Model
-----
I am planning to create a class Power which has 2 properties for voltage and Resistance.
ViewModel
---------
I am planning to create a class 'PowerViewModel' to represent the Power model. It will have two properties which will have INotifyProperty changed event.
The change from the slider has to be conveyed to the hardware and it is done through a set of uniquely identified parameter.
Such as if a slider on the PowerControl of section 2(tab2) is moved, it 'll be represented as "PC2, section2, value of slider". So, its a combination of these three things and I used to send it the hardware which displays it in the hardware display.
Here are my questions.
1- Where should I write the unique ID's? Should it be in the Model or ViewModel?
2- How should we bind the slider as per their ID's?
3- How does my Model know which slider has been moved?
4- How can we apply MVVM here?
Thanks in advance and please feel free to ask for any clarification on this.
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
I'll take a stab here...
If the IDs don't need to be in the model then they should be used in the viewmodel.
But, if you have separate objects in your view model - each associated with individual PowerViewModel objects, then you can bind those to each user control. Then you don't need IDs and the model knows what slider is moved.
Mark Salsbery
Microsoft MVP - Visual C++
modified on Tuesday, May 24, 2011 4:53 PM
|
|
|
|
|
Appreciate the quick response. I'll try it.
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
For MVVM you're kinda doing it the wrong way around - you should create your VM first and then design a view. Anyhow, I know lots of people work better visually, so:
You have five sections each with a collection of 'Voltages and resistances'
So you want a SectionViewModel that contains a collection of VoltageAndResistanceViewModels - each of which has a Voltage property and a resistance property -which utilise INotifyPropertyChanged
Then you want another ViewModel that contains a collection of the SectionViewModel
I'd say that when you instantiate each of your ViewModels you'd need to tell them which unique Id for the hardware they are representing. This information (I would htink) would be contained in the model as a series fo collectins - so you would construct your collection of ViewModels based upon these collections, hence the Model has the unique Ids, which are referenced by the viewModels
Each slider would be bound in Xaml to the appropriate property of the particular VM to which the View is bound
When the property of the Vm is changed, if necessary that's the time to adjust the property on the model - the model can then do whatever it does in order to update the machine's value.
Hope that helps at least a little!
|
|
|
|
|
Appreciate the quick response. Very well explained. I'll try it
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
I'm working on a WPF app using MWWV. I passed a data model into the CTOR of the viewmodel and set the bound properties from it.
In the view, is it possible somehow to set the width of a textbox based on the size of a field in the DB? How would you even know the width using MVVM?
Everything makes sense in someone's mind
|
|
|
|
|
Kevin Marois wrote: is it possible somehow to set the width of a textbox based on the size of a
field in the DB
Are you talking about setting the width of a textbox based on the size of the field, so if you had an NVARCHAR(50), you'd set the width for 50 characters? If you are, then your ViewModel would have a property which you'd set with this value multiplied by the width of the widest character in the font you are working with (this would normally be W in a Latin font).
In order to work out what the width of the font is, you have the choice of precalculating it and applying it as a constant, or you can use the following code:
FormattedText formattedText = new FormattedText("W", CultureInfo.GetCultureInfo("en-GB"), FlowDirection.LeftToRight, new Typeface(textBox.FontFamily.ToString()),
textBox.FontSize, Brushes.Black);
|
|
|
|
|
If the table has a name field whih is 50 characters, then I want the field on the form to be wde enough to accept 50 characters.
Everything makes sense in someone's mind
|
|
|
|
|
You are going to run into a problem with your idea... WPF UIs use TrueType fonts. For example, on my screen 10 W's are about 4x as wide as 10 i's. You'd have to size your field to fit W's since that is the widest character (in English -- USUALLY), so you'd end up with a bunch of empty space for most other characters since they are much narrower. You could switch to a fixed width font, but then it wouldn't match the rest of the UI and you'd lose various functionality / behavior from TrueType fonts.
If you still want to go down that route, Petes code snippet will allow you to calculate the width you need, then you'll need to add in some padding depending on the control.
|
|
|
|
|
Then if you follow my suggestion, you should be OK.
|
|
|
|
|
Do you need to set the width, or the maximum number of characters?
|
|
|
|
|
In this problem I have a screen displaying with the results of any operation a user performs.
It has an image control on it and the binding for source is as such:
<pre>
<Image Height="150" HorizontalAlignment="Left" Margin="94,12,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="179" Source="{Binding ElementName=isFailure, Path=IsChecked, Mode=OneWay, Converter={StaticResource ImageConverter}}" />
</pre>
The ElementName isFailure is a hidden checkbox on the form. The ViewModel sets the value to checked or unchecked for the application being in an error state. The design approach is that the image changes from thumbs up to thumbs down for a failure and one lable's text changes as well.
The text change works great. It flips back and forth easily.
The image change leaves me with a blank image window. If I manually change it either image displays fine. But programmatic change of Source fails. (Yes the class name does not match ImageConverter....ImageConverter is the name given to the ImageStateConverter in the controls Resources definition.) My ImageConverter is as follows:
<pre>
/// <summary>
/// Determines which image resource to use based on the state of a hidden checkbox on the form
/// </summary>
public class ImageStateConverter:IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return (bool)value == true
? "/SIMS;component/Views/images/thumbs_down.png"
: "/SIMS;component/Views/image/thumbs_up.png";
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
</pre>
Now I figure I have to call something on the control to force it to reload the image prior to doing a control.Show(); but I'm having trouble finding how to force it to reload the resource!
Suggestions?
Michael
|
|
|
|
|
1) Why are you getting / setting a hidden checkbox? Thats kind of hacky. Why not do it the right way with a DP or have your ViewModel implement INPC?
2) Image.Source is an ImageSource property. What you are returning is not an ImageSource. You are returning a string.
Try something like this instead:
return new BitmapImage(new Uri("pack://application:,,,/SIMS;component/Views/image/thumbs_up.png", UriKind.RelativeOrAbsolute));
Or whatever the correct path is.
|
|
|
|
|
Well,
First off I did not ask for comments on how I have a boolean passed to my binding.
Secondly the definition of the Source field is a path to the image. In this case the strings define the path to the resource within the current active assembly. Also as stated the one image worked. Turns out that the problem was in the path to the second image. Once I removed the s from images, the image loads just fine.
Finally now that both have been tested I can then do the refactoring for proper handling of the boolean.
|
|
|
|
|
Michael J. Eber wrote: First off I did not ask for comments on how I have a boolean passed to my binding.
So if someone you asked advice from spots a lousy design you don't want to hear about it. A comment like that above will not endear you to the very people you are looking to for advice. It would have been better to acknowledge the problem and thank him for pointing it out.
I thought it was an excellent answer, fixed your problem AND pointed out a lousy design issue.
Never underestimate the power of human stupidity
RAH
|
|
|
|