Click here to Skip to main content
15,889,096 members
Home / Discussions / WPF
   

WPF

 
GeneralRe: Setting an expiry date for WPF Theme DLL Pin
Prasoon Chaudhary27-Nov-11 4:30
Prasoon Chaudhary27-Nov-11 4:30 
GeneralRe: Setting an expiry date for WPF Theme DLL Pin
SledgeHammer0127-Nov-11 7:53
SledgeHammer0127-Nov-11 7:53 
GeneralRe: Setting an expiry date for WPF Theme DLL Pin
Prasoon Chaudhary27-Nov-11 18:09
Prasoon Chaudhary27-Nov-11 18:09 
QuestionWPF TreeView DataTemplate - Select Visual Parent Pin
Kevin Marois25-Nov-11 8:48
professionalKevin Marois25-Nov-11 8:48 
AnswerRe: WPF TreeView DataTemplate - Select Visual Parent Pin
SledgeHammer0126-Nov-11 10:12
SledgeHammer0126-Nov-11 10:12 
GeneralRe: WPF TreeView DataTemplate - Select Visual Parent Pin
Kevin Marois26-Nov-11 11:02
professionalKevin Marois26-Nov-11 11:02 
GeneralRe: WPF TreeView DataTemplate - Select Visual Parent Pin
Kevin Marois28-Nov-11 11:44
professionalKevin Marois28-Nov-11 11:44 
GeneralRe: WPF TreeView DataTemplate - Select Visual Parent Pin
SledgeHammer0128-Nov-11 12:02
SledgeHammer0128-Nov-11 12:02 
I'm not quite sure what you mean about having to select the part node, so you'll have to explain that further if this next part doesn't solve your issues:

There are a lot of properties that should be bindable, but are not. SelectedItem is one of them, SelectedItems on the ListView is another biggie and DialogResult is one of the biggest IMHO that should be bindable, but aren't.

You COULD use the SelectedItemChanged event in MVVM by using an Event to Command forwarder / converter, whatever the hell you want to call it. This generally looks something like:

xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"

<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding WindowLoadedCommand}" CommandParameter="{Binding ElementName=logonWindow}" />
</i:EventTrigger>
</i:Interaction.Triggers>

that assembly is part of the Blend SDK, but InvokeCommandAction doesn't let you forward the EventArgs as the command param, so you need a different forwarder I think you can copy EventToCommand out of MVVMLight... thats what I did in my MVVM framework.

BUT, all this is a bit messy and a PITA IMO because you need to add that XAML everywhere you want to trap events and you have to have the command mapper AND you need to define an ICommand to get the event and the handlers, etc.

So allow me to present alternative #2 Smile | :) ... this is what I did... for a lot of these properties (like the treeview SelectedItem and the listview SelectedItems), I added a second bindable version. VERY clean... looks just like the original property, but is now 2 way bindable. The TreeView.SelectedItem one is pretty simple:

public class TreeViewEx : TreeView
{
public static readonly DependencyProperty SelectedItemExProperty = DependencyProperty.Register("SelectedItemEx", typeof(object),
typeof(TreeViewEx), new FrameworkPropertyMetadata(null, new PropertyChangedCallback(OnSelectedItemExChanged)));

public TreeViewEx()
: base()
{
SelectedItemChanged += new RoutedPropertyChangedEventHandler<object>(TreeViewEx_SelectedItemChanged);
}


public object SelectedItemEx
{
get
{
return (object)GetValue(SelectedItemExProperty);
}

set
{
SetValue(SelectedItemExProperty, value);
}
}


private static void OnSelectedItemExChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
TreeViewEx treeView = d as TreeViewEx;

if ((object)treeView != null)
treeView.SelectItem(e.NewValue);
}

private void TreeViewEx_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{
SetValue(SelectedItemExProperty, e.NewValue);
}



}

Basically, all I do is add a SelectedItemEx DP. If the selection changes, it just updates the value of that DP to keep it in sync. If the DP changes, it updates the selected item in the treeview to go the other way.

then just switch your view to use TreeViewEx instead of TreeView and you can bind SelectedItemsEx to your VM.

-- modified 28-Nov-11 18:39pm.
GeneralRe: WPF TreeView DataTemplate - Select Visual Parent Pin
Kevin Marois28-Nov-11 12:25
professionalKevin Marois28-Nov-11 12:25 
GeneralRe: WPF TreeView DataTemplate - Select Visual Parent Pin
SledgeHammer0128-Nov-11 12:36
SledgeHammer0128-Nov-11 12:36 
QuestionCross-field validation Pin
Geysser24-Nov-11 4:39
Geysser24-Nov-11 4:39 
AnswerRe: Cross-field validation Pin
Pete O'Hanlon24-Nov-11 10:24
mvePete O'Hanlon24-Nov-11 10:24 
GeneralRe: Cross-field validation Pin
Geysser24-Nov-11 17:58
Geysser24-Nov-11 17:58 
GeneralRe: Cross-field validation Pin
Wayne Gaylard24-Nov-11 18:41
professionalWayne Gaylard24-Nov-11 18:41 
GeneralRe: Cross-field validation Pin
Geysser24-Nov-11 20:24
Geysser24-Nov-11 20:24 
GeneralRe: Cross-field validation Pin
Pete O'Hanlon24-Nov-11 22:11
mvePete O'Hanlon24-Nov-11 22:11 
GeneralRe: Cross-field validation Pin
Geysser24-Nov-11 23:33
Geysser24-Nov-11 23:33 
QuestionDataTemplate Binding Question Pin
Kevin Marois23-Nov-11 7:02
professionalKevin Marois23-Nov-11 7:02 
AnswerRe: DataTemplate Binding Question Pin
SledgeHammer0123-Nov-11 11:30
SledgeHammer0123-Nov-11 11:30 
Questionsilverlight version Pin
arkiboys23-Nov-11 6:18
arkiboys23-Nov-11 6:18 
AnswerRe: silverlight version Pin
Mark Salsbery23-Nov-11 8:57
Mark Salsbery23-Nov-11 8:57 
QuestionOpenDialog Pin
Dammie223-Nov-11 5:56
Dammie223-Nov-11 5:56 
AnswerRe: OpenDialog Pin
Pete O'Hanlon23-Nov-11 6:01
mvePete O'Hanlon23-Nov-11 6:01 
QuestionRe: OpenDialog Pin
Dammie223-Nov-11 6:11
Dammie223-Nov-11 6:11 
AnswerRe: OpenDialog Pin
Pete O'Hanlon23-Nov-11 9:04
mvePete O'Hanlon23-Nov-11 9:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.