|
- Unfortunately, the Cider designer isn't the greatest designer in the world.
But should not VS be the greatest IDE and should not WPF be its greatest UI system?
- make sure that they implement INotifyCollectionChanged
That was the reason for me to put my records in a new container.
Thanks, Harry
|
|
|
|
|
I was aiming for something that didn't say "VS Cider sucks".
|
|
|
|
|
ObservableCollection is a minimal requirement for collection binding.
|
|
|
|
|
Well, it's not really. SL and WPF don't require it for update notification, rather they rely on the internal interfaces that ObservableCollection uses.
|
|
|
|
|
I did not mean he cannot use any other collection and ObservableCollection is the only collection that can be used.
My answer should have suggested that it could be prudent to use ObservableCollection as it already includes INotifyCollectionChanged implemented.
|
|
|
|
|
Coming back to my question, what do you think: Are there other drawbacks than bad designer support in using IEnumerable?
The background is the class AutoRefreshWrapper<T> in my article AutoRefresh Entity Framework Data Using SQL Server Service Broker[^]. Should I let it implement IQueryable or ICollection in order to make cider happy?
modified 12-Jan-12 13:00pm.
|
|
|
|
|
Thanks, Collin, for your comment
In addition, it seems that I've to implement IList too, in order to enable grid editing.
|
|
|
|
|
I agree totally and that is what I meant.
If you don't need notification support, any generic collection (IEnumerable or IList ) could suffice.
However, I wanted to suggest to the OP that if he needs binding update notification, then ObservableCollection should be an option to consider. Should have clearly mentioned that in my first answer.
|
|
|
|
|
Try to avoid other collections and stick with observableCollection or a derived implementation of that. As Ilist is far slower in binding than an ObservableCollection.
http://msdn.microsoft.com/en-us/library/bb613546.aspx[^]
Quote: Data binding the ItemsSource
Update time for 1 item (ms)
To a CLR List<t> object
1656ms
To an ObservableCollection<t>
20ms
|
|
|
|
|
I'm trying to display a tooltip on the column header of a DataGridTemplateColumn . The interwebs and StackOverflow's suggestions have been surprisingly unhelpful. A nudge in the right direction would be much appreciated. Basically what I want to do is replace this:
<data:DataGridTemplateColumn x:Key="EmployeeIdColumn"
Header="Employee ID"
Width="Auto" CanUserSort="True"
SortMemberPath="EmployeeId">
with this (obviously incorrect syntax, but hopefully the intent is clear):
<data:DataGridTemplateColumn x:Key="EmployeeIdColumn"
Header="Employee ID"
TooltipService.Tooltip="The employee's ID" <-- Tooltip
Width="Auto" CanUserSort="True"
SortMemberPath="EmployeeId">
Thanks,
/ravi
modified 11-Jan-12 12:11pm.
|
|
|
|
|
NM. The last answer on this[^] page works splendidly!
/ravi
|
|
|
|
|
Hi,
I have the following demo code:
[Serializable]
[DataContract(Name = "A", Namespace = "")]
[KnownType(typeof(B))]
public class A
{
public A()
{
Id = 0;
b = new B();
}
[Key]
[DataMember]
public int Id { get; set; }
[DataMember]
public B b { get; set; }
}
[Serializable]
[DataContract(Name = "B", Namespace = "")]
public partial class B : ComplexObject
{
public B()
{
Id = 0;
Description = string.Empty;
}
[Key]
[DataMember]
public int Id { get; set; }
[DataMember]
public string Description { get; set; }
}
The problem that I am having is that the RIA service is only generating the following object:
/// <summary>
/// The 'A' entity class.
/// </summary>
[DataContract(Namespace="", Name="A")]
public sealed partial class A : Entity
{
private int _id;
#region Extensibility Method Definition
#endregion
Can anyone please help me fix this problem, or explain why it does not generate the custom "B" Property?
Thanks
|
|
|
|
|
I've got a treeview containing hyperlinks. Their source is a NodeModel.
<HierarchicalDataTemplate DataType="{x:Type models:NodeModel}"
ItemsSource="{Binding Path=Children}">
<StackPanel Orientation="Horizontal"
Margin="2">
<TextBlock Margin="0,0,5,0">
<Hyperlink NavigateUri="{Binding Caption}"
Foreground="#0C2DAA"
Command="{Binding Path=DataContext.SelectedLinkCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={ x:Type views:ProjectListView}}}">
.
.
.
The hyperlink is bound to a command:
private ICommand _SelectedLinkCommand;
public ICommand SelectedLinkCommand
{
get
{
if (_SelectedLinkCommand == null)
_SelectedLinkCommand = new RelayCommand(SelectedLinkExecuted, SelectedLinkCanExecute);
return _SelectedLinkCommand;
}
}
and the command methods:
private bool SelectedLinkCanExecute()
{
return true;
}
private void SelectedLinkExecuted()
{
}
In the SelectedLinkExecuted method, how can I get a reference to the NodeModel?
Thanks
Everything makes sense in someone's mind
|
|
|
|
|
Collin Jasnoch wrote:
The problem is getting the item. If you can find a way to get it you can pass it in using RelayComman<T>
There is no 'problem' involved in getting the item. You guys are half way to the 'correct' solution:
1) you are correct in that you have the VM expose a RelayCommand<T>. T in this case is going to be RoutedPropertyChangedEventArgs<object>.
2) the part of the puzzle that you guys are missing is an event to command mapper that is capable of forwarding the EventArgs as a command parameter.
#2 is absolutely necessary if you are writing a real MVVM app. How else are you going to forward control events to your VM?
The one I use in my MVVM framework is based off of MVVMLight's EventToCommand class. You simply create an interaction trigger for the event you are trapping and use the EventToCommand class to map it to the command and set the ForwardEventArgs=true. All via XAML.
|
|
|
|
|
Oh, my bad, I misread the OPs post. I originally read it as he was trying to click on the TreeViewItem node. He is not, so there is a much simpler way. My EventToCommand answer still stands as the "proper" way to forward control events to the VM, but that is not needed in this case.
For the sake of argument, here is how you would use the EventToCommand class:
<i:Interaction.Triggers>
<i:EventTrigger EventName="ItemKeyDown">
<wfx:EventToCommand Command="{Binding ElementName=stateCountyCtrl, Path=DataContext.KeyDownCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
You would put that in whatever object owned the event.
Then your RelayCommand<T> (the KeyDownCommand here) would take whatever EventArgs type the event is raising.
See my other response to the OP for the "correct" answer in this case.
|
|
|
|
|
Disregard the other responses in this thread as I misread your original post and thought you were trying to get the EventArgs into your VM.
In this case, you would switch your RelayCommand to RelayCommand<T> where T is NodeModel.
In your XAML, you would simply pass in the NodeModel via the CommandParameter. Add this to your Hyperlink:
CommandParameter="{Binding}"
|
|
|
|
|
This may be rather long. Please bear with me.
I am working on a WPF app. I am trying very hard to follow MVVM design practices as I understand them.
The MainWindow contains a TabControl. For each TabItem, I have created a separate UserControl in order to split things out logically and to make the XAML more manageable (there are going to be several tabs).
Each UserControl has its own ViewModel, which is instantiated in the code behind for the particular UserControl. Each UserControl/ViewModel pair is pretty much self-contained, independent of the others. There is a common Model for all of the above that handles the database end of things (each ViewModel talks to its own instance of the Model). The MainWindow does NOT have a MainWindowViewModel as I have found no need for it (all the MainWindow does is hold a text heading and the TabControl).
The thing that I am wrestling with is this: I would like to be able to prompt the end user to save any pending changes if they click into a different tab. Apparently, whenever you click on a different tab, the TabControl unloads the UserControl of the previously selected tab. The only event that seems to let me know that the user has clicked away into another tab is the Unloaded event for the UserControl. At that point, it appears to be too late to pop up a message from the User Control because it has, well, unloaded.
I discovered that I can handle the SelectionChanged event for the TabControl in the MainWindow, but the way my code is structured, there is no way to get back to the ViewModel of the tab that was deselected to make it save the changes from there.
Suggestions please...
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
There is a *gotcha* to this approach though (actually, there are a couple). First of all, when the selection changes, the TabControl has the unfortunate habit of unloading the View (hence unloading the DataContext), and rendering the new view. Second, how does he know that there's unsaved information - this relies on the binding being refreshed, which in turn, relies on the property update mechanism (in other words, is he relying on the focus being lost before the property updates).
|
|
|
|
|
Thanks Pete.
If there was just an "UnloadedPreview" event...
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
Collin Jasnoch wrote: I think you and I conversed about this before (I believe you have a blog post
about using IEditableObject... It might have been someone else though).
No, you're right - it was me.
As for the other part, I'm sorry - I misunderstood what you'd pointed out - you're entirely right that the previously selected value will be in there. I glossed right over you talking about needing a main VM, so I apologise; I really should read things more carefully.
|
|
|
|
|
Collin Jasnoch wrote: As for how to know if there is unsaved information, I did breeze over that. I guess I assumed he had some sort of business object tracking that (bad assumption though).
I'm using DevForce for the Model end of things. I can tell if there is unsaved data or not. That should not be a problem.
Collin Jasnoch wrote: I think you and I conversed about this before (I believe you have a blog post about using IEditableObject... It might have been someone else though). He of course needs to be doing something along those lines in order to properly prompt the user. Perhaps you could share that posting with him.
I would be interested in seeing that discussion.
[Edit: Pete gave me the link.]
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
Thanks Collin.
Thanks for the tip. Sounds like I need to seriously rethink my way of doing things. You have given me food for thought.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
Tom - the IEditableObject info that Collin was talking about was covered in a blog post that I wrote here[^].
|
|
|
|
|
Thanks Pete.
WE ARE DYSLEXIC OF BORG. Refutance is systile. Your a$$ will be laminated.
There are 10 kinds of people in the world: People who know binary and people who don't.
|
|
|
|
|
No problem. Glad to be able to help.
|
|
|
|