|
Yup. I'm an idiot. I spent hours trying to figure out why I'm not seeing anyting.
Thanks!
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Using VS2019, .Net framework 4.72:
I wrote a simple app that has a collection class (derived from ObservableCollection ) of items (that inherit from INotifyPropertyChanged ). I'm specifying 5 items to process.
Each of these items has a DoWork method that simply sits and spins for a randomly selected amount of time (from 1 to 30 seconds). While an item is "spinning", it updates a Progress property, as well as a Status property. The updates to these properties are intended to update the UI.
The observable collection class contains a method that does the following:
public void Start()
{
try
{
var list = this.Where(x=>x.Status == WorkerStatus.NotStarted);
Parallel.ForEach(list, this.options, worker=>
{
worker.DoWork(options.CancellationToken);
});
}
catch (OperationCanceledException ex)
{
if (ex != null) { }
}
}
I'm not getting any exceptions, but the UI updates appears to reflect item status updates all at the same time.
In an attempt to fix the update issue, I call this method from the Progress and Status property set method
private void DispatcherNotify(params string[] propertyNames)
{
Dispatcher.CurrentDispatcher.Invoke(()=>
{
foreach(string name in propertyNames)
{
this.NotifyPropertyChanged(name);
Debug.WriteLine("{0} - {1}", this.IDName, name);
}
});
}
I have verified that this method is indeed being called as expected, but the UI isn't updating (each "item" has its own UI component that is supposed to be updated).
The UI status update is handled by a converter, and that converter is called for all five items , but only when all 5 items have finished processing.
What am I doing wrong?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I would've created an ObservableCollection of "user controls" (that implement INotify).
I then invoke PropertyChanged on the user controls; which could be hosted in any type of "panel" type control.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
The items are bound to a user control.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
But you appear to be scoping the property changed to the collection, not the items.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
The user control element that is supposed to show the update is bound to the item (which is the data context). The UI does in fact update, but not while any of the 5 items is processing
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I want to collapse or expand all TreeView nodes under parent node if user holds down Left Control key and presses left mouse button on expansion arrow of tree view.
How do you do this in WPF? It's not as obvious as it was in WinForms.
|
|
|
|
|
|
As Gerry mentioned, you need to hook up a handler for the mouse click and check the status of the CTRL key.
You then go through all your child ViewModels and flip the property you databound to the IsExpanded property.
This is how you can databind the IsExpanded property (and take IsSelected along for the ride if you need it - makes it VERY easy to select an item programmatically):
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded" Value="{Binding Path=IsExpanded, Mode=TwoWay}"/>
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}"/>
</Style>
</TreeView.ItemContainerStyle>
In case you do not have a view model for your tree items you have two options:
1. Switch to WinForm
2. Introduce the view model
I supposed you could also try calling methods on the tree view control itself to find it's children, but it will be a LOT more code than the viewmodel, specifically when it start delay loading and virtualizing etc. WPF was designed for a ViewModel, and going against that is always asking for pain.
|
|
|
|
|
Hi,
I want to create a project with AvalonDock and MVVM based on the example of AvalonDock and MVVM of Ashley Davis.
I want to use the AValonDock.ManagedContent class (AvalonDock component) but in the Dirkster AvalonDock package (Dirkster99 · GitHub) the ManagedContent class in not present.
Is there a workaround or an equivalent class ?
Thanks for the answers.
|
|
|
|
|
It's been 10 years ... time marches on.
AvalonDock and MVVM
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Hi Gerry,
Thanks for the answer.
I'm read the "AvalonDock and MVVM" project of Ahsley Davis. He uses ManagedContent class of Avalon (especially in dico Dictionary<object, managedcontent=""> contentMap, ..),
but in the new AvalonDock version (of Dirkster99 Avalon free support release),
i notice that this class MangedContent does not exist.
If there is no bypass, I will do it another way (based on the Avalon example MVVMTestApp that comes with the AvalonDock source code).
Regards.
|
|
|
|
|
I'm using MahApps in my app. The data grid's column header style looks like this.
So I added this to my cell headers:
<DataGridTextColumn.HeaderStyle>
<Style TargetType="DataGridColumnHeader">
<Setter Property="HorizontalContentAlignment"
Value="Center" />
</Style>
</DataGridTextColumn.HeaderStyle>
The problem is that now the column headers have lost their style. It now looks like this
How can I apply the header alignment without loosing my grid styling?
Thanks
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
Use BasedOn.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
So I have this ListView , and I want to make a specific column have a different font family, so I tried setting the CellTemplate for the column. Because of the architecture of the app, I have to apply this template in the C# code.
I tried :
- Creating a resource like so:
<DataTemplate x:Key="PAScodeGridCell" >
<TextBlock Text="{Binding}" FontFamily="Consolas" />
</DataTemplate>
and was setting it like so:
column.CellTemplate = (DataTemplate)WpfCommon.Globals.XamlReaderLoad("PAScodeGridCell"); It found the template in the resource file, and set it to the CellTemplate property, but the font in that column wasn't Consolas.
Next, I tried so I tried specifying the template as a string in the c# code like so:
readonly string _CELL_TEMPLATE_ = string.Concat( "<DataTemplate xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">",
"<TextBlock ",
"Text=\"{{Binding Path=PAScode}}\" ",
"FontFamily=\"Consolas\" /></DataTemplate>", and set the property like so
column.CellTemplate = (DataTemplate)XamlReader.Load(xaml);
The result was no different.
By all rights, both methods should have worked. I inspected the visual tree while the app was running and it's as if the specified template wasn't applied at all.
What am I don't wrong?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|
I think I posted the wrong snippet for the first attempt. I used FindResource there.
No matter which way I tried it, the CellTemplate showed that it was set, but the column did not reflect the settings I was trying to set.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
I found the problem. This is the code that was creating the GridViewColumn:
DataTemplate cellTemplate =
Binding binding = new Binding()...
GridViewColumn column = new GridViewColumn()
{
Header = "...",
DisplayMemberBinding = binding,
CellTemplate = cellTemplate,
};
I had to change it to NOT set the DisplayMemberBinding property:
GridViewColumn column = new GridViewColumn()
{
Header = "...",
DisplayMemberBinding = (celltable == null) ? binding : null,
CellTemplate = cellTemplate,
};
And now it does exactly what I want it to do.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Glad it's working.
Might be a timing thing:
Quote: Resources can also be referenced by code from within the collection, but be aware that resources created in XAML will definitely not be accessible until after Loaded is raised by the element that declares the dictionary.
(I see now you're "creating" on the fly; I was "switching" when I looked back at my app).
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
It's a binding thing - I was using DisplayMemberBinding, and then trying to apply a template that did its own binding - you can't do both, and when you try, it always does the DisplayMemberBinding first.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
That makes sense.
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
I have an icon (resource, do not copy) in my project.
I added an Image element to my xaml.
<Image Source="pack://application,,,/Pilot128.ico" Height="24" />
The icon shows up in the designer, but not when I actually run the app.
However, when I do this, it works as expected:
<Window.Resources>
<BitmapImage x:Key="appIcon" UriSource="Pilot128.ico" />
</Window.Resources>
<Image Source="{StaticResource appIcon}" Height="24" />
Why doesn't the first way work?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
Have you tried either:
<Image Source="/Pilot128.ico" Height="24" /> or:
<Image Source="pack://application:,,,/YourAssemblyName;component/Pilot128.ico" Height="24" /> The documentation[^] seems to suggest that your URI should work, but I don't think I've ever managed to make it work.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Yeah, they both do the same thing.
I guess I'm fine with what I have to do to get this to work, but it doesn't make any sense that I *have* to do that way, unless it's because it's an ICO file as opposed to a png/jpg?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
|
|
|
|
|
|