|
I too often wondered about things like this. But I have finally come to terms that I think makes the most sense.
1) Go ahead and use the CurrentItem and force that behavior on the ViewModel. I think the hard fact is that ViewModels shouldn't be used across different presentation frameworks (e.g. WebForms, Asp.Net MVC, Windows Forms, WPF). This shouldn't happen for a multitude of reasons. The major point is your going to paint yourself into a very difficult and hard to use ViewModel to try and achieve compatibility with all of these frameworks. I have often fought with this too, and I came to some really good conclusions trying to learn the real way to treat ViewModels.
* ViewModels work best as an organizational structure. I treat ViewModels as an organization unit and not another technical layer of abstractions. This will give you optimal productivity and fewer bugs. With a well structured and organized ViewModel you create a more maintainable and agile product base. You shouldn't think about using ViewModels in "other" places than the one your creating it for, because it just doesn't work well.
* ViewModel code should be very simple. This means that the ViewModel code should be very simple that even a 2 year old can write them. Sure you can have a ViewModelBase class that contains some important infrastructure for your application, but after that your ViewModel code should be simple. With really simple viewmodel code, you can write up a ViewModel for exactly what you need in a few minutes.
Now, i know what some people are going to complain saying that they want to have a single ViewModel for everything. But with a focused and really simple to write ViewModels. It's painless to create more classes for your program to do exactly what you need.
Does this mean that your going to have a lot of ViewModels? YES.
Does this mean you have to write a ViewModel for Windows Forms and a different one for WPF? YES
If you think ViewModels should be another component of re-use, please take a look at this post from Udi about the fallacy of re-use.
http://www.udidahan.com/2009/06/07/the-fallacy-of-reuse/[^]
2) For the Commands, I like to use the RelayCommand implementation: http://msdn.microsoft.com/en-us/magazine/dd419663.aspx#id0090030[^]
This is pretty much "The" way to handle code only ViewModels. This allows to have the behavior that your looking for.
<br />
public Person SelectedPerson { get; set; }
<br />
public ICommand EditCommand { get; private set; }<br />
<br />
private void OnEdit(object arg)<br />
{<br />
}<br />
<br />
public SomeViewModel()<br />
{<br />
EditCommand = new RelayCommand(OnEdit, x => SelectedPerson != null);<br />
}<br />
This works really well, and it's very simple too!
|
|
|
|
|
I'm using VS2010. You know how when you create a new silverlight project you get a form asking which web application to connect it to?
Let's say I copy the silverlight project to another directory and load it into another solution. How do I connect that silverlight project to the web application that exists in that solution?
The only way I've found so far is to create a new blank project and copy all the classes, assets, etc. over. There has to be a much better way.
Thanks
Just for clarification when I copy a silverlight project and then add it into an existing solution and build, the xap file is updated in the old web project's Client Bin folder. So it knows about it somewhere.
Brent
|
|
|
|
|
dbrenth wrote: There has to be a much better way.
I have noticed that trying to rename all files can be much more painful (and harder to work) then actually creating a new project and copying them over. But that is just my opinion.
Someone else may have found a better way.
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I wrote a UserControl with a button inside: btn1
In the Main code, I dynamically instantiate some of my UserControl and dynamically wire an event handler to the click event of the UserControl Button btn1.
In this event Handler I want to find which object fired the event: oUserControl1, oUsercontrol2, oUserControlN ???
Thanks
Jean
public partial class MainWindow : Window
{
int i = 0;
public MainWindow()
{
InitializeComponent();
}
private void newUserControl_Click(object sender, RoutedEventArgs e)
{
MyUserControl oMyUserControl = new MyUserControl();
oMyUserControl.Name = "UC" + i;
i++;
oMyUserControl.btn1.Click += new RoutedEventHandler(btn1_Click);
MyStackPanel.Children.Add(oMyUserControl);
}
void btn1_Click(object sender, RoutedEventArgs e)
{
}
}
|
|
|
|
|
Member 2475960 wrote: private void newUserControl_Click(object sender, RoutedEventArgs e)
Check if e.OriginalSource() gives you something (e.g. the name of the initiating control).
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
You perobably need to maintain your own list of controls that you created, and in your handler do something like this:
UserControl senderCtrl = sender as UserControl;
var dynamicCtrl = (from ctrl in this.myDynamicControls
where ctrl.Equals(senderCtrl)
select ctrl).FirstOrDefault();
if (dynamicCtrl != null)
{
}
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
It's working. Not easy! Now, I've to find out why it's working I also have to find more documentation on dynamic UI in WPF
Thanks for your help
Jean
|
|
|
|
|
Hi,
I am using SilverLight DataGrid with RowDetail Template.
I am having toggleButton on click of that i want to show RowDetailTemplate which contain another child datagrid.
Problem is when i click on the second or third row of the parent grid the SelectionChanged event is not fired.But when i click on the first row toggle button it displays child datagrid.
Thanks,
Sumukh
sam
|
|
|
|
|
Hello,
I am not sure if this will help but I had a similar thing going on with a combo box in WPF. It was binded to a list of persons. The solution was to override the equals method of the person class.
|
|
|
|
|
I hope I am posting this in the correct forum - although it concerns ssrs, I think it is more a winforms / wpf question.
We have a wpf application using the winforms reportviewer. This report shows a pass / fail status and I am using wingdings font with chr(0252) to display a tick and chr(0251) to display a cross. This works really well in the report and for sending to a printer, but when exported to pdf both the characters turn info small dots - not really acceptable for our users.
I have seen multiple other posts about this issue as a known problem, there this is a post on Microsoft connect [^] that indicates it is fixed (on 5/6/2009).
I am wondering if I am missing something obvious on how to obtain a more recent version of ReportViewer that includes a fix?
Is anyone else aware of this issue or have a resolution? As this is used in quite a few different reports, I would much prefer to fix the issue, than change all the reports to use different characters or fonts.
Thanks,
Tim
|
|
|
|
|
Obviously the fix will be part of SQL Server 2008 R2 CTP3 (didn't search for release date).
So maybe wait until this fix has been released and see if it did the trick ? (I often had to wait for fixes using SSRS during past 3 years)
Or, if you don't want to wait for the fix, maybe you could use images to replace these special characters ? Rdp file's size will grow but you'll be able to display it regardless of the media.
|
|
|
|
|
Paul,
Thanks for your comments, and sorry for the slow follow up.
The connect posting was from 5/6/2009 and I thought the release had now happened (the post was from some 18 months ago).
I have now installed the ReportViewer 2010 Redistributable (v10.0 of ReportViewer), however this did not resolve the issue. Now, instead of the tick and cross turning into a dot, they turn into an empty small box.
As I have these characters contained in multiple reports, I did not want to have to change them.
Thanks for any further help.
Regards,
Tim
|
|
|
|
|
I have worked around this problem by using the characters 0080 and 0079 from the Wingdings 2 font. I think because these codes are below 127 they do get converted correctly in the pdf.
I have posted this as an issue at https://connect.microsoft.com/SQLServer/feedback/details/618435/reportviewer-does-not-export-pdf-correctly-for-wingdings-fonts.
Tim
|
|
|
|
|
Which version of the dll are you using?
Make sure you use the one that supports SL4.
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I would recommend you download Prism from here and upgrade all the Prism files you add a reference to.
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I'm sorry - I meant the codeplex site itself.
If you update all your Prism dll references things should work.
Very strange.
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I wrote some Template to button object in my xaml.
I want to have image on the button - so i wrote a Template ( code attached )
I want to bind the image source to some variable in the xaml code ( in the c# code ) and i dont know how to do it.
<Style x:Key="MyBtnTmpl" TargetType="Button">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Image Source="SomePath.png" Stretch="Fill"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
|
|
|
|
|
Create property in your code and set Source="{Binding RelativeSource={RelativeSource TemplatedParent},Path=PropertyName}" in Image tag of your control template..
|
|
|
|
|
Dim TextBlock As New TextBlock
Dim Hyperlink As Hyperlink
Dim UrlWithText() As String
Dim SampleText As String = "sample http://google.com text http://yahoo.com"
If Regex.Matches("sample http://google.com text http://yahoo.com", "(\bhttp://[^ ]+\b)").Count > 0 Then
For i As Integer = 0 To Regex.Matches(SampleText, "(\bhttp://[^ ]+\b)").Count - 1
Hyperlink = New Hyperlink() With {.NavigateUri = New Uri(Regex.Matches(SampleText, "(\bhttp://[^ ]+\b)").Item(i).Value)}
Hyperlink.Inlines.Add(Hyperlink.NavigateUri.ToString)
AddHandler Hyperlink.Click, AddressOf hyperLink_Click
URLWithText = Regex.Split(SampleText, Regex.Matches(SampleText, "(\bhttp://[^ ]+\b)").Item(i).Value)
Try
TextBlock.Inlines.Add(URLWithText(0))
TextBlock.Inlines.Add(Hyperlink)
TextBlock.Inlines.Add(URLWithText(1))
Catch
Finally
SampleText = TextBlock.Text
End Try
i += 1
Next
End If
Grid.Children.Add(TextBlock)
This is my code. This code changes the text in the URL, gives HyperLink.
"Sample http://google.com text http://yahoo.com" in
http://yahoo.com and http://google.com should be changed to a hyperlink.
But.. This is not work.
It return..
(When the URL contains two)
sample http://google.com text http://yahoo.com
or
(When the URL contains one = "sample http://google.com text")
sample
(http://google.com text is not showin).
How can fix this code? or... another way?
|
|
|
|
|
Hi all,
I have written a .Net desktop application whose UI is completely written in WPF. The application works fine on my dev machine (Windows XP).
But when I tried to run my application on a fresh VISTA machine, I could not run it. I got a message that application fails to start (kind of message).
And when I run my application on VISTA machine which already have Visual Studio 2008 installed on it, my application runs without any problem.
Can somebody let me know please what should do before running my application on a fresh VISTA (or Windows7) machine? Am I missing some .net dlls/assemblies which should be copied on a fresh machine before I run my application there?
I am also creating installer of my application. If there is something else that I should take care of while installing a .net/WPF application, please let me know.
Regards
Aseem Sharma
|
|
|
|
|
Check if you have the appropriate versions of the framework on the Vista machine.
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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
I need to create table that all ListViewItem of this table will be build hold
1. Image
2. Text
3. Button
How can i do it ?
|
|
|
|
|
This[^] article is not Silverlight but it might just help 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.
My latest tip/trick
Visit the Hindi forum here.
|
|
|
|
|
Its not in WPF - its in simple winform !
|
|
|
|
|
Use a DataTemplate for the ListViewItem, and populate it with the the items you are interested in. Obviously, these items would have to be bound items.
|
|
|
|