|
_Maxxx_ wrote: neither the view nor the viewmodel are aware of one another's existence
If you have some interaction, the View has to have knowledge of the ViewModel otherwise there is no point in the ViewModel. If you note, I carefully said that there was a containing view which was used to identify the active view by having the VM behind this simply expose a property which a DataTrigger uses to display the relevant trigger. This makes for small, single responsibility VMs with the one behind the clock being responsible for updating the time in the binding, and the one behind the container being responsible for identifying which the active clock should be.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
First, thanks for taking the time to read my waffle, let alone responding
Pete O'Hanlon wrote: the View has to have knowledge of the ViewModel
Yep - badly worded by me. What I mean is that all interaction is done via binding - the only reference in code is in the main window which sets the Content of the labels to an instance of the ClockViewModel- so the VM knows nothing at all about the view, while the view only knows of the ViewModel because its content is an instance of one, and it uses a ContentTemplateSelector to determine how to display it.
The View itself shows the time by binding to the Hours Minutes and Seconds properties of the VM - so sure, it knows there will be a Vm with these properties, but it has no reference to an instance (* of course it does, really, it's just handled by WPF and not me!)
I agree your solution works, and works fine - what I am looking at, though, is the concept more that the practicality of this particular example.
What if I want to introduce a third view? I really wanted the designer to be able to just knock up any number of views to handle the same VM without having to change the VM.
I can extend your idea to use an enumerating rather than a boolean - but again that requires that I know all of the views in advance.
So here's what I would like to happen:
I write my ClockVM with appropriate properties.
I write a TemplateSelector which, based upon something in the View, determines which template (IOW which View) to select.
The designer designs several views.
The designer adds templates to the dictionary
I add code to the Window which sets the Content of each control to it's VM - without knowledge of whether this is a digital, analogue or something else version.
Ideally then, without any code changes to the Template Selector, it just works!
This requires that the template selector has access to something in the view which tells it which template to return.
So (as a poor example) I'd like the designer to be able to put a control on the window, and set something (in Xaml) to tell the SelectTemplate method which template to select.
I think my lack of understanding of WPF is hampering me somewhat - maybe it's just not possible to do what I want (maybe it's not sensible!)
Essentially what I am working toward is the idea that a number of viewmodels can be created and given to a design team who can put the gui side of the application together with little or no help from the development team.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Hey,
Looking for some help on Binding to the selectedDates property of the calendar control.
I have an observable collection of my own appointments objects and this class has a date property. So I want the calendar control to show all the dates from the observable collection. Not sure how to do this. I know how to manually set the dates in the calendar control and they show up with the light blue box around them.
If anyone could point me in the right direction that would be great
Thanks
|
|
|
|
|
|
I'm working with .net 4.0.
So its basically saying that I cant actually bind to the SelectedDates property and have to do the work in the code behind.
|
|
|
|
|
Hi all,
I checked the validation for my form by using DataAnnotations.
<br />
[Required(ErrorMessage="User Name is Required")]<br />
[StringLength(12,MinimumLength=6,ErrorMessage="User Name must be in between 6 to 12 Characters")]<br />
public string UserName<br />
{<br />
get { return _UserName; }<br />
set <br />
{<br />
<br />
Validator.ValidateProperty(value, new ValidationContext(this, null, null) { MemberName="UserName"});<br />
_UserName = value; <br />
}<br />
} <br />
The error is always throwed at [Validator.ValidateProperty] and applicaton is stopped!! why on my friend's PC is not and the error message is displayed near the textbox normally.
The strange is any source code that i got from internet or from my friend's PC is run normally with DataAnotation. But when i clean project and build it again, the application always throw error ( like : value is required ... ) at Validator.ValidateProperty and application is exited ( or stop running )
How could i solve it ?
|
|
|
|
|
Hi,
I want to develop a web site in silverlight completely,It's a website for getting advertisments.
Will I encouner any problem?
I mean it is OK if develop a web site fully in silverlight
Best wishes
|
|
|
|
|
mehrdadc48 wrote: Will I encouner any problem?
What types of problem you are expecting there?
mehrdadc48 wrote: I mean it is OK if develop a web site fully in silverlight
Why not? There are several websites now fully developed in Silverlight.
Don't forget to Click on [Vote] and [Good Answer] on the posts that helped you.
Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets | Silverlight Tutorial
|
|
|
|
|
See this interesting discussion here[^].
Might give you some confidence to start developing in Silverlight.
|
|
|
|
|
OK, I'm playing with WPF MVVM
I'm using a resource dictionary to define which view to be used for which viewmodel.
e.g.
<DataTemplate DataType="{x:Type vm:ClockViewModel}">
<vw:DigitalClock/>
</DataTemplate>
then in my Window code behind I have
ClockViewModel vm1 = new ClockViewModel();
tabItem1.Content = vm1;
Sofa so good - but in this particular case I have a clock model - and I can choose either a digital or analogue view. The default in the dictionary is the digital clock.
I know I could stop using the dictionary and simply instantiate the view myself and give it a ClockViewModel as a DataSource, but I rather like the elegance of the Dictionary.
I can't figure out if it is possible to keep using the dictionary, but override the process on occasion.
Remember, I'm a WPF newbie, so if I am missing something obvious, be gentle
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I think you can make use of template selector concept. You can create a user control with DataTemplateSelector, check property in your view model and switch between analog and digital clock usercontrols accordingly.
Try Google for some tutorials,
DataTemplateSelector WPF[^]
|
|
|
|
|
Thanks - I'm Binging it now (not really, I'm googling).
Sometimes it's just finding that right keyword...
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Googled, found, implemented and Bobn's your Uncle - thanks!
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
_Maxxx_ wrote: Bobn's your Uncle
Bob's your uncle
I guess you use DataTemplateSelector.right?
|
|
|
|
|
Arun Jacob wrote: Bob's your uncle
Actually, Bob's transgender so now Bob's your aunt.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I'd start looking into DependencyInjection if I were you.
Maybe even Prism ...
|
|
|
|
|
Hi,
I took a class for youtube player and create a instance of that youtube player in Page3.xaml page..The issue is at runtime (F5), in the application i got the youtube video in the bottom of the page and even its there for each and every xaml pae while i am navigating..how to resolve this issue for setting the youtube video exact position where i want and stop reflecting to other pages .The code is as below:
in Class1.cs
-------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Browser;
namespace K12
{
public class YouTubePlayer : IDisposable
{
public const int DefaultWidth = 425;
public const int DefaultHeight = 344;
#region Private properties
private string uniqueId = Guid.NewGuid().ToString();
private double top;
private double left;
private double height = DefaultHeight;
private double width = DefaultWidth;
private string videoId;
private bool isEmbeded;
private HtmlElement div;
#endregion
public YouTubePlayer(string videoId)
{
this.videoId = videoId;
}
public double Top
{
get { return top; }
set
{
top = value;
if (isEmbeded)
{
SetStyleProperty(DivId, "top", "\"" + (int)top + "px\"");
}
}
}
public double Left
{
get { return left; }
set
{
left = value;
if (isEmbeded)
{
SetStyleProperty(DivId, "left", "\"" + (int)left + "px\"");
}
}
}
public double Height
{
get { return height; }
set
{
height = value;
if (isEmbeded)
{
SetAllDivsProperty("height", "\"" + (int)height + "px\"");
}
}
}
public double Width
{
get { return width; }
set
{
width = value;
if (isEmbeded)
{
SetAllDivsProperty("width", "\"" + (int)width + "px\"");
}
}
}
public bool AllowFullScreen { get; set; }
public void Embed()
{
if (isEmbeded) return;
isEmbeded = true;
div = HtmlPage.Document.CreateElement("div");
div.SetAttribute("id", DivId);
div.SetAttribute("style", "position: absolute; width:" + (int)Width + "px; height:" + (int)Height + "px; top: " + (int)Top + "px; left: " + (int)Left + "px; z-index:10");
div.SetProperty("innerHTML",
"<object width=\"" + (int)Width + "\" height=\"" + (int)Height + "\" id=\"" + ObjectId + "\">" +
"<param name=\"movie\" value=\"http://www.youtube.com/v/" + videoId + "&hl=en&fs=1\"></param>" +
"<param name=\"allowFullScreen\" value=\"" + AllowFullScreen + "\"></param>" +
"<embed id=\"" + EmbedId + "\" src=\"http://www.youtube.com/v/" + videoId + "&hl=en&fs=1\" type=\"application/x-shockwave-flash\" allowfullscreen=\"" + AllowFullScreen + "\" width=\"" + (int)Width + "\" height=\"" + (int)Height + "\"></embed>" +
"</object>"
);
HtmlPage.Document.Body.AppendChild(div);
}
public void Dispose()
{
if (!isEmbeded) return;
isEmbeded = false;
HtmlPage.Document.Body.RemoveChild(div);
}
#region Implementation
private string DivId { get { return "YouTubePlayer" + uniqueId; } }
private string ObjectId { get { return "YouTubePlayer_Object_" + uniqueId; } }
private string EmbedId { get { return "YouTubePlayer_Embed_" + uniqueId; } }
private void SetAllDivsProperty(string property, object value)
{
SetProperty(DivId, property, value);
SetProperty(ObjectId, property, value);
SetProperty(EmbedId, property, value);
}
private void SetProperty(string divId, string property, object value)
{
HtmlPage.Window.Eval("document.getElementById(\"" + divId + "\")." + property + " = " + value + ";");
}
private void SetStyleProperty(string divId, string property, object value)
{
HtmlPage.Window.Eval("document.getElementById(\"" + divId + "\").style." + property + " = " + value + ";");
}
#endregion
}
}
In Page3.xaml.cs
----------------
private void Page3_Loaded(object sender, System.Windows.RoutedEventArgs e)
{
YouTubePlayer player = new YouTubePlayer("5_a4zb9D4m4")
{
Top = 100,
Left = 200,
Width = 400,
Height = 400
};
player.Embed();
}
Plz suggest me..Thanks in Advance
With Regards
Ch.Gayatri
|
|
|
|
|
In the WinForm days there was a lot of work done with anchoring to make controls adjust to resizing of the window.
What is the equivalent approach in WPF applications? What are best practices for scaling controls? Implement with inline code or what?
Thanks
|
|
|
|
|
HorizontalAlignment="Strech" VerticalAlignment="Strech"
This might do the job...
|
|
|
|
|
Thanks, I'll give it a try.
|
|
|
|
|
One of the great things about WPF is that you don't need this sort of thing anymore!
|
|
|
|
|
Windows Presentation Foundation (WPF) was going to hopefully usher in a new era of cool applications and user interactions.
That's why I'm learning this days about the amazing tool from Microsoft wich named "Expression Blend 4". It makes our work easier than ever to design our WPF and Silverlight apps,Particularly impressive to me is the SketchFlow feature, which enables rapid prototyping for our WPF and Silverlight applications.Meanwhile the ability to creat rich web experiences, games, desktop apps, and more.
When i Was seaching for samples or examples for a great WPF project on the web, I found some apps like http://bit.ly/9RSD1Y , http://bit.ly/bRTdYg but they are not avaible to download ,such as payante libraries like Devexpress,Infragistrics and more ..
I'm searching for first exemplar for WPF on CodePlex, to not only learn WPF but also to learn good practices for enterprise application development across the board.
|
|
|
|
|
Dear,
I think so, for any WPF learner MSDN is the best resource
find the below URL
http://msdn.microsoft.com/en-us/library/ms754130.aspx[^]
I would suggest, if you want to know best practices for specific area then go to Google.
Thanks
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
Hi All! I've started learning WPF but stuck. How could I preserve transparent background in the DataGrid->DataGridTextColumn->Cell during edit mode?
Thanks in advance!
<br />
<Style TargetType="{x:Type my:DataGridCell}"><br />
<Setter Property="Template"><br />
<Setter.Value><br />
<ControlTemplate TargetType="{x:Type my:DataGridCell}"><br />
<Border SnapsToDevicePixels="True" VerticalAlignment="Stretch" Background="Transparent" HorizontalAlignment="Stretch" BorderBrush="{TemplateBinding BorderBrush}"><br />
<ContentPresenter Name="ContentPresenter" VerticalAlignment="Center" Content="{TemplateBinding Content}" TextBlock.TextAlignment="Left" SnapsToDevicePixels="True" TextBlock.Foreground="#FF5185F2"><br />
</ContentPresenter><br />
</Border><br />
</ControlTemplate><br />
</Setter.Value><br />
</Setter><br />
</Style><br />
modified on Thursday, July 15, 2010 1:07 PM
|
|
|
|
|
I want to develop tcp socket application,forwhich want to use c++ tcp server and silverlight tcp client(web client).At server filling data in a structure and sending to the client,Is there any way to retain the values of the structure at client side?Or can i serialize the sending data as a class object in silverlight?
|
|
|
|