|
Yes, this makes sense.
The PropertyObserver constructor attaches to the current value (this.SelectedJobAssignment ) of the passed property.
It does not automatically track if that property itself changes. (I.e., it doesn't notice if this.SelectedJobAssignment changes)
The registration tracks if the referenced property of that value changes. (I.e., it only notices if this.SelectedJobAssignment.PhaseStart changes)
|
|
|
|
|
Why not move it into the SelectedJobAssignment 's Setter ?
|
|
|
|
|
In ref to this and your prior posting....
I see how it works, it just looks kludgy.
First, I could see something like
propertyObserver.Register(typeof(theType), x => x.Property, MyHandler());
this way you can register multiple type, and only need to have this on one place.
Having to re-register each time the property changes is ugly
If it's not broken, fix it until it is
|
|
|
|
|
You just use a different property observer.
One for "the class" that checks when specific properties are changed.
In the handlers for that observers, you register handlers for the properties on the values of the "properties of the class".
This way the PropertyObserver handles the general case.
|
|
|
|
|
Ya I know. THe idea is great, just not the cleanest implementation.
If it's not broken, fix it until it is
|
|
|
|
|
Hi,
Simply you can achieve this by using triggers.
Write an Event Trigger with event name as Click and bind an ICommand property which is in the viewmodel.
So whenever there is a click on the checkbox(either select or deselect this method triggers)
Then you can write the logic according to your functionality.
There are so many ways to achieve this as well.
|
|
|
|
|
I'm trying to bind a window's Activated event to a command:
So I have:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
and
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="..\AppResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Activated">
<i:InvokeCommandAction Command="{Binding WindowActivatedCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
</ResourceDictionary>
</Window.Resources>
I get a compilation error
"Property 'Triggers' is not attachable to elements of type 'ResourceDictionary'"
What's wrong here??
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Move it outside the Window.Resources section. All you need do is add it after the opening Window tag.
|
|
|
|
|
Thanks Pete. That did it.
The Getter for the command fires, but the execute never does.
My code is pretty standard:
private ICommand _WindowActivatedCommand;
public ICommand WindowActivatedCommand
{
get
{
if (_WindowActivatedCommand == null)
_WindowActivatedCommand = new RelayCommand(p => windowActivated(), p => windowCanActivate());
return _WindowActivatedCommand;
}
}
private bool windowCanActivate()
{
return true;
}
private void windowActivated()
{
}
Neither windowCanActivate nor windowActivated ever fire. How do I know if the Event is calling the command?
If it's not broken, fix it until it is
|
|
|
|
|
How have you assigned your DataContext?
|
|
|
|
|
Yes.
If it's not broken, fix it until it is
|
|
|
|
|
I think you need to read my question again.
|
|
|
|
|
About the DC? Yes, I assigned it.
This window is working. It's just THIS piece that's not working.
If it's not broken, fix it until it is
|
|
|
|
|
I asked how have you assigned the DC, not have you assigned it? It's entirely possible that you have created it after the Activated event has fired.
|
|
|
|
|
oh oh, my bad. I'm sorry. I totally missed the word 'how'
I did it in the code behind after the InitializeComponent.
If it's not broken, fix it until it is
|
|
|
|
|
It's my fault - I just reread your post - the getter is being hit, so the DataContext has been hooked up.
In order to test your Activated event, bring another window to the front and then reselect your application. See if it fires then (it should).
|
|
|
|
|
You're right - it fired AFTER I re-activated it.
It just doesn't fire on startup, which is what I want.
[UPDATE]
According to this[^]
the Window is activated when "The window is first opened."
The Activate command fires AFTER I lose and regain focus, but not on first startup.
[UPDATE 2]
I replaced the command with the event subscription in the code begind and it DOES fire on startup, so for some reason the command isn't firing until later on.
If it's not broken, fix it until it is
modified 3-Mar-14 18:57pm.
|
|
|
|
|
FYI - Resolved this using the Loaded event.
If it's not broken, fix it until it is
|
|
|
|
|
Hmmmm. Downvote countered.
|
|
|
|
|
I have 2 view model in main window
In which i have 1 button in one view model, while in my other view model i have a panel and initially tht panel is visible=fALSE
I want tht while i click on tht button the panel from another view model will be visible
|
|
|
|
|
Well, you could always look at using an EventAggregator.
|
|
|
|
|
Kind of a newbie question. In my XAML I have these 2 lines
<DataGridComboBoxColumn SelectedItemBinding="{Binding ExpenseCategory}" Header="Category" />
<DataGridTextColumn Binding="{Binding ExpenseCategory}" Header="Category"/>
The first one WILL NOT display the value but the second one will. I created the second line to test my sanity [and the binding].
In the viewmodel I've exposed a
List<string> that I had initially bound to the combobox column's ItemsSource. However, when the column failed to display any data I removed it to see if that made a difference. With the List bound to the ItemsSource there was no value for the bound ExpenseCategory property and nothing in the list of values. That XAML was simply:
<DataGridComboBoxColumn SelectedItemBinding="{Binding ExpenseCategory}" ItemsSource="{Binding ExpTypes}" Header="Category"/>
So...what am I missing here? Why won't the combobox column display my data?
|
|
|
|
|
FWIW - and I have no idea if this is even close to an optimal approach - I found this solution in an old article by Julie Lerman http://msdn.microsoft.com/en-us/magazine/gg983481.aspx[^]
<DataGridTemplateColumn Header="Category" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=ExpenseCategory}" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<Grid FocusManager.FocusedElement="{Binding ElementName= taskCombo}" >
<ComboBox x:Name="taskCombo" SelectedItem ="{Binding Path=ExpenseCategory}"
IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding ExpTypes, Source={StaticResource vm}}"/>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
In her article she explains that the Grid FocusManager is used to manage the events when a new row is created and the user's first click is in the combobox.
This approach seems to work OK, but it is far from straightforward and I hope that somebody here has a better solution that would allow the DataGridComboboxColumn to work for me.
|
|
|
|
|
How about combining the two approaches? Since you've already managed to get the viewmodel into a static resource, something like this should work:
<DataGridComboBoxColumn
SelectedItemBinding="{Binding ExpenseCategory}"
ItemsSource="{Binding ExpTypes, Source={StaticResource vm}}"
Header="Category"
/>
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks for the reply. I've been crawling my way towards that solution by incrementally melding some of the elements of Julie Lerman's approach with a DataGridComboBoxColumn, just hadn't gotten all the way to the one you've suggested. However, I've just tried your code and it works. Much more concise.
Probably should have mentioned in the original question that I'd taken the [non-working] syntax directly from MSDN's latest example for combo box columns, and that had me flummoxed.
|
|
|
|