|
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?
|
|
|
|
|
if you write your data in xml-format you will have a easy and portable solution.
Press F1 for help or google it.
Greetings from Germany
|
|
|
|
|
The c++ server already have a native c++ client, now we need to add a Silverlight client without any modification to the server.
The applications are biased to use minimal data transfer. so we cannot use xml ( which will also create changes in server )
Recreating the data byte-by-byte is possible at client, but we would like to know of other possible methods.
|
|
|
|
|
Here is the problem:
I have a DatePicker control (Framework 4.0) and once I delete the text in its textbox, a phrase "Enter text here" (enclosed in <> brackets) appears in a text box.
I need to get rid of it, so when the user deletes the text in a DatePicker's textbox, the textbox remains empty.
So far I've tried to examine DatePicker's code via reflector, but haven't found any clues.
Any help will be greatly appreciated.
|
|
|
|
|
Found this[^] thread. Could be of some help to you.
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 Guys,
i want to do the styling in the C# area.. like as we do in the XAML.
for a button i have given the style in xaml and i need to give the same in C#..
Eg;
<Button Canvas.Left="559" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Canvas.Top="515.403" Height="23.634" Width="59" FontFamily="./Fonts\#Verdana" FontSize="10" FontWeight="Normal" FontStyle="Normal" TabIndex="8" Name="Refresh" Click="Refresh_Click" Background="Transparent">
</Button>
here i have given the style as
Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}"
i need to give the same in C# as
Style style = new Style(typeof(Button));
---- here how to do that thing . can any body help.. thanks in advacne..
Refresh.Style = style;
|
|
|
|
|
Step 1: Creat Resource (Style) in your XAML code.
Step 2: Use method FindResource in C# code i.e.
Refresh.Style = (Style)FindResource("XYZStyle");
Parwej Ahamad
ahamad.parwej@gmail.com
|
|
|
|
|
How do we get the ASCII value of key entered in a silverlight textbox, using C#.
Reqmt : Disabling Ctrl +V in silverlight textbox
Request your attention
Thanks
Santhosh
Santhosh
|
|
|
|
|
See this thread[^].
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.
|
|
|
|
|
WPF DataGrid and asp.net like editItemTemplate? Is it supported out of the box?
Thanks
dev
|
|
|
|