|
Ok. First, this is my code.(TextBlock add to the Grid)
for (int i = 0; i < 10; i++)
{
TextBlock TextBlock = new TextBlock();
TextBlock.Inlines.Add(i);
Grid.SetColumn(TextBlock, 1);
Grid.SetRow(TextBlock, Grid1.RowDefinitions.Count - 1);
Grid1.Children.Add(TextBlock);
}
And the result is
1
2
3
4
5
...
But, I want TextBlock add to the reverse order.
...
5
4
3
2
1
How can do this?
|
|
|
|
|
Try this
for (int i = 10; i > 0; i--)
Reverse the order that you traverse the numbers
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Uh.. that code is just sample.
Inline content in the TextBlock, the other goes.
|
|
|
|
|
Change the way you are viewing the problem. Assume that you will bind to the data, and then use a CollectionViewSource to manipulate the way you view the data - it's very easy to sort the data in the view without having to change it's underlying order in any way.
|
|
|
|
|
Have a look at the Grid.SetRow method[^].
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.
|
|
|
|
|
OK. I saw that article.
but.. I don't know in detail.
I have attempted below whatnot.
Grid.SetRow(TextBlock, Grid1.RowDefinitions.Count + 1);
or Grid.SetRow(TextBlock, Grid1.RowDefinitions.Count + 2);
but this isn`t work..
|
|
|
|
|
Try TextBox.SetRow() ; (if such a method shows up, I have not tried this before but it might be worth a try).
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.
|
|
|
|
|
Im converting a project from C# to VB (I know - I'm in HELL). I have a base class derived from UserControl , and have several controls derived from the base class. None of these objects are in their own namespace.
When I try to compile the app, I get the following error for all of the controls:
D:\dev\Silverlight\...\UserControls\MyControl.g.vb(41) : error BC30002: Type 'MyProject.MyBaseControl' is not defined.
The xaml looks like this:
<my:MyBaseObj x:Class="MyProject.MyControl"
xmlns:my="clr-namespace:MyProject">
The .vb code looks like this:
public partial class MyBaseObj
Inherits UserControl
end class
public partial class MyControl
Inherits MyBaseObj
end class
I tried creating a simple test project with a similar arrangement of files, and it compiles fine. I have no idea why it's doing this.
================ UPDATE:
When I try to define the xmlns namespace entry in the Xaml file, intellisense claims it can't find the namespace, even though I used intellisense to define the xmlns namespace entry. Because it can't find the namespace in the project, it doesn't show any objects when I try to define the user control itself (in the Xaml).
.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
modified on Monday, November 22, 2010 9:44 AM
|
|
|
|
|
I must this inheritance looks a little convoluted.
MyControl inherits myBase and my:myBase is MyProject.MyControl.
Could that be creating some sort of cyclic reference.
Anyway, you could try a 'clean solution' - fixes things sometimes.
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.
modified on Saturday, November 20, 2010 8:28 AM
|
|
|
|
|
I don't think it's convoluted at all. All of the classes are in the same folder with no namespace declared. How can there be any circular references when the namespace is the same for all of the classes (except the root one, of course)?
MyControl --->MyBase --->UserControl
How is that convoluted (or even circular)? BTW, the actual source files compile fine - it's the .g.vb files that are not.
I *did* try a "clean solution" (and stated as much in my OP), and it compiles just fine. But when I try the same thing in my project, it doesn't compile with errors in the .g.vb files. The same code (in the original C# app) compiled just fine.
.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
|
|
|
|
|
FWIW I have has a similar issue that I couldn't see what was causing the problem. Eventually I gave up. next time I restarted VS2010 it just compiled fine!. never did find out why.
I'm guessing you already restarted VS, but thought it worth mentioning.
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I actually rebooted the system. These are the only errors remaining in the project, and it's really pissing me off.
.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
|
|
|
|
|
Actually not specifically MVVM or even specifically WPF - but this is what I need help on...
I have a CustomerDetailsView and I have a CustomerDetailsViewModel
This view shows (obviously) a single customer's details.
I also want a list of customers that the user can search.
So - my initial thought was to have a collection of CustomerDetailsViewModels which I bind to something in a CustomerListView. so I have a CustomerListviewModel with a property of ObservableCollection<customerlistviewmodel>
but that strikes me as being wrong.
I really only want to show the customer first and surname in the list (let's say) - not the whole address, order values etc.
So my next thought was not to use a ViewModel collection at all, but just a collection of - What? customer models? Customer list models?
The ViewModel that 'displays' the list needs to be ignorant of the actual view - it just demands that there is a list of customers from which the user can select one, which will send a command back to the View model.
But because it doesn't know how this list is to be displayed, should it provide a collection of some ViewModel or other, each element injected into a view so I have a collection of views and associated view models that can then be shown in some sort of list?
Or do I provide a collection of data to which the grid (or whatever) binds?
I guess what the question boils down to is:
Is each element in a 'grid' displayed to the user a View with an associated ViewModel?
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
My eyes crossed about 3/4 through that trying to keep track of the collections.
caveat - I am fairly fresh into the MVVM scene!
I would not consider having a collection of views or viewmodels. I only deal with collections of models. My models are based on database views that include all the FK descriptors that are required by the VIEW. Note only descriptors not any sub collections.
So I would have a collection of customer models (it may be a filtered collection based on the environment). In my VM base I have a static method that takes a shallow copy of the collection or object, this disconnects the new collection from the important collection and allows me to add defaults etc into the list. This is then used to populate combo controls. All are observablecollections
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: My eyes crossed about 3/4 through that trying to keep track of the collections.
yeah - sorry! In my defence, it was written last thing on friday before I left work.
Now it is later Friday and I am pissed - so I won't try.
I'm just checking out a couple of MVVM sites
This one is quite nice[^]
and listening to a hHanselminute blog
here[^]
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I use the galasoft framework such that it is. Very minimalist.
As for Friday night, mine is just starting, a nice bottle of white, maybe a tequila taler and some sort of liqueur after dinner.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The general rule is that you only retrieve and handle what the view needs to display. So, for instance, if your view doesn't need the full address then you don't retrieve it. I always get nervous when I see ViewModels binding to ViewModels which in turn may bind to other ViewModels. This is missing the point of what the VM is actually for.
|
|
|
|
|
Yeah - I'm beginning to think that the VM is for two things:
1. To control a View's logic
2. To provide a view with data
I'm beginning to wonder whether I should have two classes
1. A ViewController
2. A ViewData
The ViewData object is the provide of data for that particular view.
The ViewController handles any commands required for that view
The ViewController would need to be the View's DataContext - so would need a property of ViewData - but that seems more senisble to me than having a ViewModel with a whole heap of properties as well as a whole heap of command logic.
whadya reckon?
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
I think this is one abstraction too many, especially as one of the things you might want to do with a VM is decide whether or not you want to be able to execute a command which may well depend on the value of some properties. Plus, where would your validation fit in all of this?
|
|
|
|
|
Essentially I'm just thinking that a VM, rather than having several properties which are bound to, has one ViewData property - which would 'contain' all of the properties that traditionally would be in the VM.
So if the ability of a command to execute depends on a member of the ViewData object - all well and good.
If the ability of a command to execute depends on some other criteria, then the VM would expose a property which the View could bind to for this purpose.
The former is a purely data-based rule, the latter some business logic rule - hence sensible separation, no?
it's like the application says
"Hey - I want to display this Customer data and let the user modify it, but the phone number can only be changed by an administrator"
The ViewModel goes and gets (or is given) a Customer Model.
The ViewModel creates a ViewData object exposing the model properties.
Additionally the ViewModel has a property IsAdministrator
The View uses IsAdministrator to determine whether the Phone Number is changeable - but this data isn't part of the ViewData
As for validation - frankly I haven't looked at validation in WPF/MVVM at all yet, so I'm not sure where the validation would go in the traditional model, let alone in this embryonic idea of a model!
If you have any good references for MVVM WPF validation I'd be interested in taking a look.
thanks for taking the time
max
___________________________________________
.\\axxx
(That's an 'M')
|
|
|
|
|
|
Wrong place for this post mate.
You could post this as a tip trick or configure your blog to appear on CP.
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.
|
|
|
|
|
|
Hi, in our win forms program we get the bitmap of an activeX control (its the Microsoft mappoint control) using the PrintWindow() function in User32.dll, this works fine.
Now we are moving our program over to wpf. The technique still works as it did until the activeX control is not visible, any part of the control that is not showing on the screen justs comes out as black.
It is as if in wpf the control is not drawn unless it is on screen.
Is there a way we can force it to draw the bitmap of the control?
thanks.
|
|
|
|
|
Hi,
How to roll(automatically moving from bottom to top) data in datagrid in silverlight?
please help me..
|
|
|
|