|
I didn't read your entire post (waaay too long), but I think your issue is that you are putting an ItemsControl inside of your list box and then ListBoxItems inside of the ItemsControls. Thats not quite right. Set ItemsSource on the ListBox and template only the ListBoxItems themselves. Everything will work that way.
|
|
|
|
|
Hi thanks for your reply
Yes my post is too long and I did read the posting guidelines before posting but how are good people like you supposed to help without all of the information?
Yes I can make the listbox look and function as I would expect a listbox to function with this.
<ListBox
ItemsSource="{Binding Path=AvailablePitchbookChartFamily}"
DisplayMemberPath="DisplayName"
>
</ListBox>
The issue is that the type OptionViewModel implements INotifyPropertyChanged. A collection of this type is bound to my Listbox. However the act of changing a selected item does not fire the PropertyChanged event and therefore doesn't update the underlying business object being modelled. I've been trying to structure the listbox in a way that it looks just like a listbox but the PropertyChanged event does fire when a listbox item is selected/deselected. My lack of WPF knowledge is currently stopping me from achieving this.
Anyway I'll keep improving my knowledge. I think I'll end up doing something with the IObservable interface.
Thanks for your help
|
|
|
|
|
The ListBox fires a SelectionChanged event when the selection changes, so you can do what you want in 2 ways... 1) bind the SelectedItem to a property in your VM using 2 way binding, or 2) tie the SelectionChanged event to a command in your VM so your command handler gets called when the selection changes
#2 is a bit trickier to implement, both are acceptable. #2 is preferable though when you want to do something when the selection changes.
|
|
|
|
|
I have a View and ViewModel. View has a TreeView in it. I want to detect when the user double clicks on a **TreeViewItem**, not the actual tree itself. Whats the common way to do this? I want to somehow bind that event to a RelayCommand in the ViewModel.
I'm familiar with System.Windows.Interactivity and Interaction.Triggers, and that works fine for events coming from the TreeView itself, but it doesn't seem possible to put it in a TreeViewItem style, etc or trap events from TreeViewItem.
I had a vague idea, but I'll hold that until I get some responses... it seems kind of hacky .
|
|
|
|
|
So you have one half of the answer with using the EventToCommand behavior to hook up to the relevant command. The other half depends on how you populate the TreeView - if you use the TreeView.ItemTemplate, then you can attach it in there, e.g.
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Countries}">
<TextBlock Text="{Binding Name}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction CommandName="DoubleClickCommand" CommandParameter="{Binding Name}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
|
|
|
|
|
Tricky, tricky .
|
|
|
|
|
That's me - Captain MacTricky of the Clan Tricky.
|
|
|
|
|
Hmm... this doesn't actually work. Unless I'm missing something obvious.
<TreeView ItemsSource="{Binding StateCountyItems}" FocusVisualStyle="{x:Null}" BorderThickness="0,0,0,0">
<TreeView.ItemTemplate>
<HierarchicalDataTemplate ItemsSource="{Binding Value}">
<TextBlock Text="{Binding Key}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="MouseDoubleClick">
<i:InvokeCommandAction CommandName="Test" />
</i:EventTrigger>
</i:Interaction.Triggers>
</TextBlock>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
My ViewModel has:
public RelayCommand Test
{
get
{
if (_test == null)
_test = new RelayCommand(t);
return _test;
}
}
private void t()
{
}
With that XAML exactly, the Test getter is never even called. I changed CommandName to Command="{Binding ElementName=g, Path=DataContext.Test}"
g is the window that has its DataContext set... I'll of course clean up the names later lol... when I change it to that, NOW the Test getter is called, BUT void t() is never called when I double click.
any ideas?
|
|
|
|
|
Hmm... when I change the event to PreviewMouseMove, then the handler gets called, but not for MouseDoubleClick. Works for PreviewMouseLeftButtonDown and MouseLeftButtonDown and other events. Guess the double click is getting eaten. Son of a... ![Frown | :(](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_frown.gif)
|
|
|
|
|
Hmmm. That's not great. I suspect the TreeView is consuming it for its own purposes then (e.g. opening/closing nodes).
|
|
|
|
|
I was able to trap the MouseLeftButtonDown and check MouseButtonEventArgs.ClickCount == 2. Good enough I suppose.
|
|
|
|
|
|
Pete O'Hanlon wrote: Ouch. I hate hacks.
And you work with MS technology. hic!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Don't see how it's that big of a hack anyways... if the treeview is eating the message, there isn't any other way .
|
|
|
|
|
POHs words were innacurate, I'd call it a work around, its what we do, every framework has shortcomings and it is up to us to work around them to achieve our requirements. Kludge is another valid description, something that works but you are not happy with the way it does it. Elegant on the other hand is what we aspire to!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Mycroft Holmes wrote: Kludge is another valid description, something that works but you are not happy
with the way it does it
Or, to put it another way, a hack. So my words were accurate.
|
|
|
|
|
It's a hack, because you don't have any chance to deal with the message you want to. It's not a criticism of your code - just that you shouldn't have to do that. It's at odds with the templated nature of WPF because while you can restyle the UI, you can't restyle the behaviour of the interactions without having to work round it. So, it's a hack.
|
|
|
|
|
hello,
i'm working in wpf application
and using pages
i'm show this pages in frame control
all my page opening in this frame
my questions
how close a page and delete it in navigation from frame
how clear my pages from frame control
Greeting
sayed eltokhy
hello every body
i'm sayed from in egypt
i like vb.net
|
|
|
|
|
I apologise if I haven't quite understood your requirements here, but are you trying to remove the journal entry? If so, you can use NavigationService.RemoveBackEntry to remove a page from the navigation journal.
|
|
|
|
|
I'm finally getting around to trying to learn WPF anyone know of a good resource site to start learning from?
Lobster Thermidor aux crevettes with a Mornay sauce, served in a Provençale manner with shallots and aubergines, garnished with truffle pate, brandy and a fried egg on top and Spam - Monty Python Spam Sketch
|
|
|
|
|
Try here
Lists the blogs of the masters of WPF....sort of... and a couple of CPians that I don't know why are there.....
You know I'm kidding: Pete and Sacha
"Whether you think you can, or you think you can't--either way, you are right." — Henry Ford
"When I waste my time, I only use the best, Code Project...don't leave home without it." — Slacker007
|
|
|
|
|
Soulus83 wrote: a couple of CPians that I don't know why are there
I have compromising photos of Josh Smith using an iPad.
|
|
|
|
|
If you're already comfortable in .NET programming (C# or VB) then I would (and did) read through the entire SDK documentation. Then do it again.
Windows Presentation Foundation[^]
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm working on a new project, so I'm going w/ MVVM from the ground up... trying to stick to 100% "proper" MVVM and deleting the code behinds (and the subsequent InitializeComponent() call)... seems like this works fine for windows & dialogs, but seems to be an issue for a UserControl. Is it possible to have a UserControl without calling InitializeComponent()? I have an attached property on the usercontrol.xaml for the viewlocator, but even that is not getting called.
|
|
|
|
|
SledgeHammer01 wrote: trying to stick to 100% "proper" MVVM and deleting the code behinds
That's not a requirement of MVVM, and nor should it be. InitializeComponent is a very important method call.
I don't know where this zero-code-behind idea comes from. All MVVM requires is that you don't put model code in the code-behind. It's still acceptable to have a code behind, where you might want to trigger an animation for instance.
|
|
|
|