|
Ian,
You are correct in the way DataContext is set. I am using a method learned from one of the MVVM mechanism described on a tutorial published in CodeProject, I forget the Authors name right now, search WPF MVVM.
As mentioned in another comment, I do somehow have this working and will publish my fixes here when I have got close to understanding how I fixed it. Something to do wth the MetaData part and creating an instance of the list in the constructor. Like I said, I will put my changes up as soon as I can.
I also appreciate that I may have a single list instance issue as mentioned by SledgeHammer.
Again, thanks for your time, there is nothing worse than head butting a brick wall.
Just racking up the postings
|
|
|
|
|
1) First issue I see is that your dependency properties are set up incorrectly.
Think about whats happening here... SelectedItemsProperty and DeSelectedItemsProperty are static (meaning a single instance in this case). You have set the values to new ObservableCollection<object>(). What you end up with is *EVERY* DualListControl in the world is using the same ObservableCollection<object>(). You also allow users to overwrite the collections completely. Not something you want to do.
Use DependencyProperty.RegisterReadOnly() to register the property as a read-only DP and create the ObservableCollection<object>() in the public DualListControl() constructor. Something like:
public DualListControl()
{
SetValue(SelectedItemsPropertyKey, new ObservableCollection<object>());
}
then remove the setters for those properties.
2) Bindings in generic.xaml should be TemplateBinding, not binding.
|
|
|
|
|
SledgeHammer, Thanks for your time and comments
Re point one,
DependancyProperties obviously still confuse the life out of me!
I tried making this a readonly collection and then realised what you are suggesting, you have given me the method required if I want a single list for all DualListControls right? but these can no longer be ovverriden by a user.
That is not my intention, what I am trying to achieve and failing is to be allow a developer to do something like this
<Grid>
<CustomControls:DualListControl Name="List" SelectedItems="{Binding SelectedItemsA}" DeSelectedItems="{Binding DeslectedItemsA}"/>
</Grid>
The problem I appear to have is that the SelectedItems dependancy property is not being bound to the one in the MainAppViewModel.
Re point two,
Ian has already found this and corrected me, the bindings in the Generic.xaml are now as the follows
<ListView Grid.Column="2" Name="ElementSelectedList" ItemsSource="{TemplateBinding SelectedItems}"/>
Have I understood this correctly?
Just racking up the postings
|
|
|
|
|
No, what you have *NOW* will result in every DualListControl sharing the same ObservableCollection instance. I'll assume that you want each one to have its own. The solution I gave you will give each instance its own collection.
The UserControl doesn't have its DataContext set, so those Binding will not work.
The bindings in Generic.xaml should be TemplateBinding.
|
|
|
|
|
SledgeHammer,
I appreciate your time.
I understand your point about a single list instance being shared amongst all controls. Please understand that I have been making changes as recommended by yourself and Ian (above).
The complication that arises with the ReadOnly method you describe is that I would like to be able to allow the consumer to use the control in the following way. The ReadOnly method does not allow me to do this.
Any suggestions?
<CustomControls:DualListControl SelectedItems="{Binding SelectedItemsA}" DeSelectedItems="{Binding DeSelectedItemsA}" Width="300" Height="300"/>
Regarding the DataContext, the control template does not appear to require the DataContext specifically set as the ViewModel is implicitly bound to the parent view and therefore to this control, I have verified this while debugging.
I do have the control working as intended but only tested as a single instance at the moment, I will test with mutiple instances to enable me to fix the single list instance issue you have kindly pointed out.
Once again, thanks for your time.
Just racking up the postings
|
|
|
|
|
Ok... So, what you are initially doing is having every instance of your control share the same instance of ObservableCollection. However, you do allow the user to overwrite said instance through your property setter. That will cause you *many* problems down the road with data binding. One area where WPF crumbles hard is when you start switching around instances of objects or creating temporary objects, etc. because it depends on those being the same object to function.
Now, C# doesn't have pointers, but I will use them to illustrate what I am trying to explain.
1) you create your control, your control creates an ObservableCollection() [0x1000]
2) a user of your control subscribes to [0x1000].CollectionChanges
3) a user calls your setter with a new ObservableCollection() [0x2000]
Guess what happened? Everybody subscribing to the [0x1000] collection events is now broken. Everybody making changes to the [0x1000] collection is broken as well. [0x1000] is now orphaned.
What you want is for each instance of your control to create its own ObservableCollection and *NEVER* let anybody change that. It is important that if you created [0x1000], that it remains [0x1000] for the lifetime of your control. Otherwise bad things will happen.
Now, the read-only DP will not fulfil your just mentioned requirement of binding to collections. Fair enough.
What you are trying to do here is combining TWO techniques into ONE which will cause you the problems just mentioned.
If you look at the ListView or TreeView for example, you will see the proper way to lay out your control.
public ObservableCollection<???> Items // this *MUST* be read-only
{
get { ... }
}
public IEnumerable ItemsSource /// this is how people will pass in collections
{
get { ... }
set { ... }
}
So what happens here is that people can add items manually to the Items collection OR use the ItemsSource to pass in collections.
If you only need to allow passing in collections, use the IEnumerable ItemsSource method instead.
If you want to support both, you need to add some "protection" code...
i.e. don't allow use of Items if ItemsSource is not null and vice versa, etc.
|
|
|
|
|
Hi,
I am building a silverlight app in vs2010 premium edition.
I do not seem to be able to find the option where I can change the windows from the default tabs to mdi windows.
Any thoughts please?
|
|
|
|
|
You could have done better to post this question in the Visual Studio section[^].
However, for your answer, just double clicking on the window should make it 'float'.
Or you could right click on the code window title bar and select 'float'.
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 am in the process of building a monitoring application for the daily import processes...
The app should check the status of the services running on various servers.
It should also keep track of the errors, frequency of loads, etc.
So basically it acts like an admin/control page.
Can you recommend a UI for me to look at so that I can get a feel of what the UI should look like to cater for such requirements ?
Regards
|
|
|
|
|
Nagios / Centreon would be a good start obviously.
|
|
|
|
|
Do not understand what you mean.
Please explain.
Thanks
|
|
|
|
|
arkiboys wrote: Can you recommend a UI for me to look at so that I can get a feel of what the UI should look like to cater for such requirements ?
I was just answering your question
Nagios is a web solution to monitor servers and services accross networks ; Centreon is a web interface to configure Nagios. If you are searching for ideas about UI design with such requirements, you should take a look at these products.
|
|
|
|
|
I have code that leaves garbage on the window. need to rePaint .
couldnt find an invalidate that I knew how to use.
I probably clean up nice.
|
|
|
|
|
You don't. WPF manages all that. If you are leaving garbage on the screen, you are doing something wrong. Please explain what you are doing.
|
|
|
|
|
I was using standard message boxes in nested foreach loops to see if I was iterating
through the Directory properly , using DirectoryInfo. and when the loops were finished. it left the last message box image over the window.
I probably clean up nice.
|
|
|
|
|
However I noticed (by accident) that If I turned off the IDE while the test app was running,
then it wasnt a problem , but it still brought up the question and so I appreaciate you're
answer.
I probably clean up nice.
|
|
|
|
|
Hello!
This is a new article on Silverlight Prism development (tips and real practical examples). Enjoy reading. http://www.enterra-inc.com/techzone/silverlight-prism-overview-part-1-theory/
|
|
|
|
|
If you want to post an article here, fine. But do NOT post a link to an article on another web site.
.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
|
|
|
|
|
This is my code.
Image imgMessage = new Image();
BitmapImage bi = new BitmapImage();
bi.BeginInit();
bi.UriSource = new Uri(@"/imgMessage.png", UriKind.RelativeOrAbsolute);
bi.EndInit();
imgMessage.Source = bi;
TextBlock tb = new TextBlock();
InlineUIContainer iuc = new InlineUIContainer(imgMessage);
tb.Inlines.Add(iuc);
Grid1.Children.Add(tb);
Image shows a TextBlock within the code.
But, isn`t work!
However, when I write XAML code .. It work!
<Grid Height="312" Width="505" Name="Grid1">
<TextBlock Height="58" HorizontalAlignment="Left" Margin="88,120,0,0" Name="textBlock1" Text="TextBlock" VerticalAlignment="Top" Width="314">
<InlineUIContainer>
<Image Source="Reply.png"></Image>
</InlineUIContainer>
</TextBlock>
</Grid>
What's wrong?
modified on Wednesday, December 1, 2010 5:08 AM
|
|
|
|
|
Hi,
Given the recent "turbulence" in the "reality distortion field" of Microsoft in the WPF/Silverlight arena triggered by Muglia at PDF, then moderated by ScottGu's blog, and others ... and the presence of (new oil in old lamps ?) the emerging paradigm of :
resurrected JavaScript (thanks to jQuery and other libraries)
+
HTML 5
-
Flash
=
RIA uber alles browsers
... and in the context of the Apple-Adobe-Flash contretemps ... all obscured by clouds of marketing rhetoric regarding next year's tablets, and Android this vs. WP7 this, vs. Palm this vs. Cocoa that ... in the mobile space ...
We'd love to see on CP a round-robin between some of you real SL/WPF gurus (you know who you are) about the future of WPF/SilverLight in the next two years.
Thought about posting this on the "Site Bugs / Suggestions" forum, but feel it would be out of place there.
Personal bias: to the extent you've got to load-up, and master, some complex 3rd. party structural engine (framework) to give you a fundamentally sound application architecture (MVC, MVVM, or whatever) ... or handle complex binding, or injection of control, etc. ... there's a fundamental deficit in the basic technology.
Personal bias: the new initiatives ... for ASP.NET ... announced by MS such as the Razor view engine:
http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx
Are "late to the game" overlays that (in addition to "reaching out" to PhP developers?) ... for right now ... make sorting out the implications for the future of WPF and SilverLight more difficult ... at least for this old guy
from the ... genuinely curious ... Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
-- Modified Monday, November 29, 2010 4:54 AM
|
|
|
|
|
My ill-informed view is Silverlight has legs as a LOB solution. Why?
Although there are some great rich UI web interfaces out there, they are few and far between. Most ASP/PHP/... web form sites are weak compared to Winforms.
Silverlight offers a rich UI experience with the zero deployment strategies of web based technologies. For me that makes Silverlight a winner.
HTML5 sounds good but I bet you'll see the same cross browser issues we all struggle with today.
|
|
|
|
|
Perhaps you might want to view the Firestarter event. Clickety[^].
|
|
|
|
|
Thanks, Pete, I have signed up for the FireStarter Event.
I have also acquired Matthew McDonald's (one of my favorite technical writers) latest book 'Pro WPF in C# 2010: Windows Presentation Foundation in .NET 4.0,' and intend to review Andrew Troelsen's content on WPF in 'Pro C# 2010 and the .NET 4 Platform, Fifth Edition,' and hope to "clear the decks," and bone-up to get the most out of the FireStarter Event ... whatever that will be.
What the technical book/resource for SilverLight ... comparable to McDonald's latest for WPF ... would be, I don't know, but am all "all ears" for any recommendations.
I must admit I am fascinated by what appears to me to be the "triumph" of jQuery, and its adaptation by everyone under the sun including Planet MS.
best, Bill
"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844
|
|
|
|
|
BillWoodruff wrote: What the technical book/resource for SilverLight ... comparable to McDonald's latest for WPF ... would be, I don't know, but am all "all ears" for any recommendations.
Well, I could recommend my good friend Laurent Bugnion's book, Silverlight Unleased. It's actually 2 books because you get the PDF of Silverlight 2 Unleashed to go with the Silverlight 4 tome.
I have to admit to a bias here. As a member of the WPF Disciples (which also includes Silverlight), I have a vested interest in these technologies working. As part of my take on this, I would have to point out that the tooling/technologies for HTML 5 as a ratified standard don't exist yet. Yes, there are lots of interesting implementations out there, but HTML 5 is not a stable standard, and I suspect that we are going to see a repeat of the browser wars where different vendors introduce proprietary features to differentiate their implementations.
Yes, I'm excited by some of the features of HTML 5. The Canvas alone is a huge leap forward, but while jquery provides an excellent front end for javascript, it still requires significantly more effort to develop complex apps using HTML/CSS/JavaScript than it does with something like Silverlight. More importantly, HTML 5 is not really designed to run on a desktop environment. Imagine trying to write an application such as 3D Studio Max in HTML 5 - it's just not feasible.
|
|
|
|
|