|
WebBrowserControl has a NavigateToString [^]method - can you not use that?
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Oh I was checking out methods and properties of WebBrowser control didn't see that.
Thanks for tip
dev
|
|
|
|
|
|
To be fair, I think this is a TDD question rather than specifically WPF - but it is the use of the messanger in MVVM in WPF that is causing the issue - hence the post here...
WPF with MVVM using the bare bones of the MvvmFoundation.
public CustomerSelectionAndSummaryViewModel(IController controller, FrameworkElement view)
: base(controller, view)
{
controller.Messenger.Register(Controller.MSG_Customer_SELECTED, new Action<CustomerListItemViewData>(ProcessSelection));
CustomerSelectionViewModel = new CustomerSelectionViewModel(controller);
CustomerSummaryViewModel = new CustomerSummaryViewModel(controller);
}
#endregion
private void ProcessSelection(CustomerListItemViewData CustomerListItemViewData)
{
CustomerSummaryViewModel.ViewData = Controller.GetCustomerSummaryViewData((int) CustomerListItemViewData.CustomerId);
Controller.CustomerSelected((int) CustomerListItemViewData.CustomerId);
}
Briefly, the Constructor is passed an IController - which is just a helper class, and a view (which we can ignore for these purposes)
The base class for our ViewModel stores the IController in a property.
YOu can see I register the message for a customer being selected - so that when a customer is selected I can action the selection. The rest of the constructor just instantiates a couple of other View Models that are children of this one- again this can be ignored.
So the Action passed to the Messenger.Register method 'points to' the ProcessSelection method.
Here I am saying, when something sends the Customer_SELECTED message, this ViewModel wants to handle it by executing the ProcessSelection method.
With me so far? Good Ho!
I've made the method private because the other developers are just plain stoopid (I'm a sole developer on this one, in fact, but ITRW...) and if it's not private they might decide to use it directly, which is NAGT (Not A Good Thing)
OK so, I hear you ask, what's the prob?
I want to be a good little dev and use some tests. I'd like to test the ProcessSelection() method somehow, to ensure that it calls the CustomerSelected() method with the selected Customer ID when passed a valid CustomerListItemViewData.
So (bear in mind I'm very new to TDD here)
The main stumbling block for me here is that the method is private - and I'd like it to remain so.
I can see this being a problem with these messages flying about (as the project expands) as the ViewModels are likely to use private methods to implement the functionality required when handling the message.
Many people seem to say that you shouldn't test private methods. Fair enough - but in this case shouldn't I be testing the functionality of the system when a Customer is selected?
I'm thinking that this particular private method is, in essence, public because it can be executed (be sending a message) from outside of its class. So, perhaps this is a more generic question.
The only alternate option I can think of right now would be to not test this method, but instead test the method by sending the message..?
OK - I've waffled enough! I'm, hoping you have the stamina to read through this and help me out - if not, well, it's been cathartic writing it anyhoo.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
You're right. You don't test the private method - you test the code that calls the private method. The easiest way, as you have identified, is to send the message and see what the effect is. Your test doesn't have to be complicated at all.
|
|
|
|
|
Thanks Pete,
This is a long, uphill struggle - but maybe there'll be an article at the end of it all!
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
Cool. Looking forward to seeing it.
|
|
|
|
|
Hello,
I'm new in sorting and not sure how to write the sorting code in order to sort list view by clicking column headers.
I have list view with several columns in my WPF application.
I want to sort list view by clicking any column header.
The list view is populated with data from database using data binding in this way:
List<TestName> lstTestNames = client.GetAllTestNames().ToList();
lstvTestNames.ItemsSource = null;
lstvTestNames.ItemsSource = lstTestNames;
The columns are as usual, ID, string data, date/time date and so on.
The XAML code looks as follows:
<ListView Name="lstvTestNames" Height="360" HorizontalAlignment="Left" Margin="20,33,0,0" VerticalAlignment="Top" Width="465" SelectionChanged="lstvTestNames_SelectionChanged">
<ListView.View>
<GridView>
<GridViewColumn Width="50" DisplayMemberBinding="{Binding Path=test_name_id}">
<GridViewColumnHeader Name="Sort1" Click="GridViewColumnHeader_Click">ID</GridViewColumnHeader>
</GridViewColumn>
...
The sorting code should be in click handler:
private void GridViewColumnHeader_Click(object sender, RoutedEventArgs e)
{
GridViewColumnHeader column = sender as GridViewColumnHeader;
...
}
But, how does it look like?
One additional question. If I want to sort list view by ID column that contains IDs from database,
I suppose all those values are strings (maybe not?).
But, I need integer values. How to handle this?
Thank you in advance.
Goran
modified on Thursday, January 27, 2011 7:38 AM
|
|
|
|
|
Take a look at the sort()[^] method of the class.
I must get a clever new signature for 2011.
|
|
|
|
|
As I can see Sort method for WPF list view doesn't exist.
|
|
|
|
|
Well there seem to be lots of suggestions here[^].
I must get a clever new signature for 2011.
|
|
|
|
|
Thank you very much, but I've already checked them and nothing simple was there. So, it means, I haven't found what I'm looking for. I would be thankful if somebody can write some code here.
Thank you in advance.
|
|
|
|
|
Tesic Goran wrote: I've already checked them and nothing simple was there.
Well I've just been reading the article in the first link on that page, and it seemed pretty simple to me, even though I am not a WPF expert.
Tesic Goran wrote: I would be thankful if somebody can write some code here.
I don't think that's going to happen.
I must get a clever new signature for 2011.
|
|
|
|
|
Surprisingly, sorting ListView in WPF is not a simple problem. It requires you to write lots of code. And I mean lots of code[^]!
I suggest that if you are not restricted to older (i.e. pre-4.0) versions of WPF, try using DataGrid instead of ListView. It is a lot more powerful - for one, it gives you sorting for free, and it does not take too much effort to learn if you know ListView. In one of our projects, I replaced several ListView objects and added editing to one of them in about a day.
|
|
|
|
|
It's not really complicated,
using System.ComponentModel
ICollectionView view = CollectionViewSource.GetDefaultView(lstvTestNames.ItemsSource);
view.SortDescriptions.Add(new SortDescription("test_name_id", ListSortDirection.Ascending));
|
|
|
|
|
This solved my problem.
Thank you very much.
|
|
|
|
|
Hello,
i search an pdf to xaml wrapper?
already exists such a thing? Or must I programming it new ?
thx,
benny
|
|
|
|
|
That would be a pretty cool form generating tool. Have fun with that
You can only be young once. But you can always be immature.
- Dave Barry
|
|
|
|
|
On binding large volume of data (say 1500 - 2000) row in Silverlight datagrid.. It throws error.
Does the datagrid has a maximum limit.
Santhosh
|
|
|
|
|
Throw us a bone here. What error gets thrown? When you post a question about an exception, it's generally useful to say what the exception is so that we can help, otherwise we are just going to be randomly guessing.
|
|
|
|
|
HI Pete
Thanks for the prompt reply...
error thrown in output window is
A first chance exception of type 'System.Windows.Ria.DomainOperationException'
Santhosh
|
|
|
|
|
Ah yes. One of the more unhelpful messages. You'll need to use WCF tracing to identify what's really going on. You'll need to add the following to your config file:
<system.serviceModel>
<diagnostics>
<messageLogging logEntireMessage="true" logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
</system.serviceModel>
<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Verbose, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add type="System.Diagnostics.ConsoleTraceListener" name="console">
<filter type="" />
</add>
<add name="ServiceModelTraceListener">
<filter type="" />
</add>
</listeners>
</source>
<source name="System.ServiceModel.MessageLogging" switchValue="Verbose, ActivityTracing">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type="" />
</add>
<add type="System.Diagnostics.ConsoleTraceListener" name="console">
<filter type="" />
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type="" />
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="C:\logging\wcftracesvc.log"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
<add initializeData="C:\logging\wcfmsgsvc.log"
type="System.Diagnostics.XmlWriterTraceListener, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type="" />
</add>
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
|
|
|
|
|
Hi Pete..
Thanks again..
But one other query : does the SL datagrid has any limit on its maximum record size..
Santhosh
|
|
|
|
|
No. The only limit you'll run into with the datagrid is memory.
|
|
|
|
|
No the SL Datagrid does not have a maximum limit.
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
|
|
|
|